Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter clonica

    (@clonica)

    Finally I find a solution by adding this code in the functions.php of my active theme:

    add_action( 'pre_get_posts', 'jdn_modify_query' );
    function jdn_modify_query( $query ) {
     
    	// First, make sure this isn't the admin and is the main query, otherwise bail
    	if( is_admin() || ! $query->is_main_query() )
    	return;
    	 
    	// If this is a search result query
    	if( $query->is_search() ) {
    		// Gather all searchable post types
    		$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
    		// Define the post_type you want to exclude from the results
    		$post_type_to_remove = 'product';
    		// Make sure you got the proper results, and that your post type is in the results
    		if( is_array( $in_search_post_types ) && in_array( $post_type_to_remove, $in_search_post_types ) ) {
    			// Remove the post type from the array
    			unset( $in_search_post_types[ $post_type_to_remove ] );
    			// set the query to the remaining searchable post types
    			$query->set( 'post_type', $in_search_post_types );
    		}
    	}
    }

    This way you remove ALL the products from the search results.

    • This reply was modified 7 years, 8 months ago by clonica.
    Thread Starter clonica

    (@clonica)

    Doh! I was testing it while logged in…

    By the way, is it possible to minify/combin css/js outside the <head> tag?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)