[Resolved] Remove column layout from search results

Home Forums Support [Resolved] Remove column layout from search results

Home Forums Support Remove column layout from search results

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2278169
    George

    I am only including a custom post type Courses in the navigation and WP search results, like this:

    //Limit navigation results to Courses
    add_filter( 'generate_navigation_search_output', function() {
        printf(  
            '<form method="get" class="search-form navigation-search" action="%1$s">
                <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
                <input type="hidden" name="post_type" value="courses" />
            </form>', 
            esc_url( home_url( '/' ) ), 
            esc_attr( get_search_query() ),   
            esc_attr_x( 'Search', 'label', 'generatepress' ) 
        ); 
    } );
    
    function searchfilter($query) {
     
        if ($query->is_search && !is_admin() ) {
            $query->set('post_type','courses');
        }
     
    return $query;
    }
     
    add_filter('pre_get_posts','searchfilter');

    It works as expected. Now, I would like to not display search results in columns (default Customizer behavior), like this:

    //Remove columns for search results
    add_filter( 'option_generate_blog_settings', 'gm_custom_search_results_page_settings' );
    function gm_custom_search_results_page_settings( $options ) {
        if ( is_search() ) {
    		$options['column_layout'] = false;
        }
    
        return $options;
    }

    Results are still being displayed as columns, though.

    #2278373
    David
    Staff
    Customer Support

    Hi George,

    try this instead:

    add_filter( 'generate_blog_columns', function( $columns ) {
        if ( is_search()  ) {
            return false;
        }
        return $columns;
    } );

    If that doesn’t work then your other query is interfering the the is_search condition and we’ll need to think of something else

    #2278376
    George

    That’s it, thanks, David!

    #2278427
    David
    Staff
    Customer Support

    Glad to hear that!

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