Archived topic
Customizing Search Results - CPT's / Products
5 replies · Started by Brett on October 26, 2017
Heya!
I have a few sites on the go at the moment and they all require specific search results to be displayed.
One site requires only WooCommerce products to show in the search results.
Another site requires a selection of CPT's (with all posts, pages, products hidden).
Can I do this with some PHP?
I guess I'm looking for info on how to add or hide post types from search results.
Cheers,
Brett
Hi there,
This should help: https://docs.generatepress.com/article/generate_navigation_search_output/
Hi Leo,
i see the page you linekd, but i don't understand how i can haide product of woocommerce from search results.
Can help me?
Hi there,
This should help: https://wordpress.stackexchange.com/a/231376/90661
To specify multiple post types, do this:
add_action( 'pre_get_posts', function( $query ) {
if( ! is_admin() && is_search() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'page', 'post' ) );
}
} );
Thanks Tom,
works perfect :D
You're welcome :)