WordPress default search and Woocommerce product search -
i have problem when trying search work both default wordpress blog search , woocommerce product search , can't seem find solution anywhere. have in functions.php right is:
function wp_search_filter($query) { if ( $query->is_search ) { $query->set( 'post_type', 'post' ); } if ( function_exists( 'is_woocommerce' ) ) : if ( $query->is_search && is_woocommerce() ) { $query->set( 'post_type', 'product' ); } endif; return $query; } add_filter('pre_get_posts','wp_search_filter');
but product search not work. ideas?
to answer own question, in case needs solution, came works. problem here is_woocommerce() condition not firing on search results template. around used code:
function wp_search_filter($query) { $url = 'http://' . $_server['server_name'] . $_server['request_uri']; if ( (strpos($url,'post_type=product') !== false) && is_search() ) { $query->set('post_type', 'product'); } return $query; } add_filter('pre_get_posts','wp_search_filter');
Comments
Post a Comment