Archived topic
Problems with search results layout
8 replies · Started by George on April 12, 2020
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.
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;
} );
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.
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.
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.
Also, the forum results display the load more button even with few results. Is it possible to have pagination there?
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 );
}
} );
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!
You're welcome :)