Archived topic
CPT Column Filter Breaking Layout >=3 columns
11 replies · Started by Kevin on November 25, 2018
Hi there,
On a brand new installation of WordPress, GeneratePress theme and GP Premium, I am using a filter to set the number of columns on a custom post type archive.
https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns
add_filter( 'generate_blog_get_column_count','kpry_search_column_count' );
function kpry_search_column_count( $count ) {
if ( is_post_type_archive() ) {
return 33;
}
return $count;
}
I am getting unexpected results when setting 3 or more columns:
- Only two columns per row
- Large spacing between columns
I know the filter is working because each time I change it the layout changes - just not what I expect it to change to.
Screenshots
https://imgur.com/a/mPJWl6b
Thank you.
Hi there,
Any chance you can link us to the site in question?
You can edit the original topic and use the private URL field.
Let me know :)
Hi Leo,
I have added the URL in the private URL field. I can provide WP and FTP credentials upon request.
Can you try returning a string instead of a number?:
add_filter( 'generate_blog_get_column_count','kpry_search_column_count' );
function kpry_search_column_count( $count ) {
if ( is_post_type_archive() ) {
return '33';
}
return $count;
}
Let me know :)
A string does not change the symptom. Thank you.
Ah, looks like a bug.
For now, you can do this instead:
add_filter( 'option_generate_blog_settings', function( $settings ) {
$settings['columns'] = '33';
return $settings;
} );
Thanks Tom. Great theme! Great support!
Thanks! :)
Hi Tom, I am wondering if this bug has been fixed and pushed out yet?
I ask because the code you suggested resets the "global" column settings in the customizer, therefore affecting all archives:
add_filter( 'option_generate_blog_settings', function( $settings ) {
if ( is_post_type_archive( 'team_member' ) ) {
$settings['columns'] = '33';
return $settings;
}
} );
I'd love to use the filter but if the bug is still being resolved, is there another way I can conditionally use 3 column layout only on a custom post type archive?
Thanks!
It's been fixed in GPP 1.8.
For now, you can do this:
add_filter( 'option_generate_blog_settings', function( $settings ) {
if ( is_post_type_archive( 'team_member' ) ) {
$settings['columns'] = '33';
}
return $settings;
} );
Thanks Tom. You are awesome.
Glad I could help :)