Site logo

[Resolved] generate_blog_columns filter affecting Query Loop block in sidebar

Home Forums Support [Resolved] generate_blog_columns filter affecting Query Loop block in sidebar

Home Forums Support generate_blog_columns filter affecting Query Loop block in sidebar

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2352032
    Mike

    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

    #2353548
    Fernando
    Customer Support

    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

    #2356374
    Mike

    That did the trick. Thank you very much Fernando!

    #2357004
    Fernando
    Customer Support

    You’re welcome James!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.