Site logo

Archived topic

generate_blog_columns filter affecting Query Loop block in sidebar

3 replies · Started by Mike on September 23, 2022

Viewing posts 1–4 of 4

Hello,

I'm using the generate_blog_columns filter to add columns to all post type archives and generate_blog_get_column_count to customize. This is working correctly.

add_filter( 'generate_blog_columns', function( $columns ) {
  if ( get_post_type() && ! is_singular() ) {
    return true;
  }

  return $columns;
} );

add_filter( 'generate_blog_get_column_count', function( $columns ) {
  if ( 'classified' === get_post_type() && ! is_singular() ) {
    return 50;
  }
  if ( 'event' === get_post_type() && ! is_singular() ) {
    return 0;
  }

  return $columns;
} );

The issue is when I have a Query Loop block in the sidebar the column layout is also applied there.
The issue is also only present on the archive pages that are using a GP sidebar layout element.
The homepage is using the default WP widget layout and the issue is not present.

I thought perhaps excluding the gp_elements post type in the filter above would fix the issue but it does not.

Hoping you guys have some suggestions! Thank you

GeneratePress: 3.1.3
GP Premium: 2.1.2
GenerateBlocks: 1.6.0-rc1
GenerateBlocks Pro: 1.4.0-rc1

Hi James,

Try adding this Snippet:

add_filter( 'post_class', function( $classes ) {
	if ( is_archive() && in_array( 'gb-query-loop-item', $classes ) ) {
		$index = array_search('generate-columns',$classes);
if($index !== FALSE){
    unset($classes[$index]);
}
		
	}

	return $classes;
} );

Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

That did the trick. Thank you very much Fernando!

You're welcome James!

This archived topic is closed to new replies.