[Resolved] Problems with search results layout

Home Forums Support Problems with search results layout

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1236513
    George

    I have my blog layout to not display as columns but I am using the following code to display columns on the Tutorials which is a custom post type category and News pages (news pages is the default blog):

    add_filter( 'generate_blog_columns','gm_portfolio_columns' );
    function gm_portfolio_columns( $columns ) {
        if ( is_category( 'tutorials' ) || is_post_type_archive( 'tutorial' ) || is_archive() ) {
            return true;
        }
        return $columns;
    }

    It works but the Tutorials search results do not display as columns. On top of that, the Forums search results (bbPress) display as columns and I would like the forum search results to display as per Blog layout settings.

    #1236669
    Tom
    Lead Developer
    Lead Developer

    Hey George,

    How are search results for tutorials determined? Just when the “tutorials” search term is entered?

    You could try something like this to handle everything:

    add_filter( 'generate_blog_columns', function( $columns ) {
        if ( is_category( 'tutorials' ) || is_post_type_archive( 'tutorial' ) || is_archive() ) {
            return true;
        }
    
        if ( is_search() && 'tutorials' === $_GET['s'] ) {
            return true;
        }
    
        if ( function_exists( 'bbp_is_search' ) && bbp_is_search() ) {
            return false;
        }
    
        return $columns;
    } );
    #1236674
    George

    Hi Tom.

    How are search results for tutorials determined? Just when the “tutorials” search term is entered?

    You can search for tutorials on the tutorials page on the header through the search bar. Just type a relevant keyword from the tutorials underneath to get some results.

    I put your code in, still the same behavior, though.

    #1236677
    Tom
    Lead Developer
    Lead Developer

    Strange, give this a shot to fix the forum search:

    .forum-search .generate-columns-container:not(.masonry-container), 
    .forum-search .generate-columns-container:not(.masonry-container) .generate-columns {
        display: block;
    }
    
    .forum-search article {
        width: 100%;
    }

    The GP columns won’t work properly in the bbPress search itself due to the HTML markup, so the above should just force full width.

    #1236681
    George

    Great, that fixed the forum search results. The tutorial search results still display as per blog layout and not as columns. Just enter “wordpress” in the Tutorials search bar to get some results.

    #1236683
    George

    Also, the forum results display the load more button even with few results. Is it possible to have pagination there?

    #1237556
    Tom
    Lead Developer
    Lead Developer

    For the tutorials, try this:

    add_filter( 'generate_blog_columns', function( $columns ) {
    
        if ( is_search() && isset( $_GET['post_types'] ) && 'tutorial' === $_GET['post_types'] ) {
            return true;
        }
    
        return $columns;
    } );

    For the load more, try this:

    add_action( 'wp', function() {
        if ( function_exists( 'is_bbpress' ) && is_bbpress() ) {
            remove_action( 'generate_after_main_content', 'generate_blog_load_more', 20 );
        }
    } );
    #1237720
    George

    Nailed it, Tom.

    Here is the final code:

    add_filter( 'generate_blog_columns', function( $columns ) {
        if ( is_category( 'tutorials' ) || is_post_type_archive( 'tutorial' ) || is_archive() ) {
            return true;
        }
      
       if ( is_search() && isset( $_GET['post_types'] ) && 'tutorial' === $_GET['post_types'] ) {
            return true;
        }
    
        if ( is_search() && 'tutorials' === $_GET['s'] ) {
            return true;
        }
    
        if ( function_exists( 'bbp_is_search' ) && bbp_is_search() ) {
            return false;
        }
    
        return $columns;
    } );
    
    add_action( 'wp', function() {
        if ( function_exists( 'is_bbpress' ) && is_bbpress() ) {
            remove_action( 'generate_after_main_content', 'generate_blog_load_more', 20 );
        }
    } );

    Thank you, once more!

    #1237962
    Tom
    Lead Developer
    Lead Developer
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.