Try adding the return as well in the else{}
, like this:
function template_chooser($template)
{
global $wp_query;
$post_type = get_query_var('post_type');
if( $wp_query->is_search && $post_type == 'product' )
{
return locate_template('archive-products.php');
} else {
$args = array_merge( $wp_query->query, array( 'post_type' => 'post' ) );
query_posts( $args );
return locate_template('archive-products.php');
}
return $template;
}
add_filter('template_include', 'template_chooser');
Haven’t tested.
Related Posts:
- Exclude a term of a taxonomy with a custom post type in a search
- Set meta_query only for specific post type
- WooCommerce product search titles only
- filter custom post type by meta key in dashboard
- WordPress sort search results by custom order
- WooCommerce sort products by the actual product width(not the shipping width)
- search suggest – filter post type
- Search filter triggered & sort by custom post type
- Blank search results on custom search
- Modifying search results based on post_type
- Search in multiple specific post types
- Diffrent search templates for different post types
- custom post type Search returns No Results in admin panel
- Genesis filterable portfolio isotope [closed]
- Get post from custom post type order by two taxonomies
- How can I see a list of my Custom Post Types of the last term I was in?
- Search Custom Post Type & Taxonomies
- Filtering WP_Query
- Multiple meta_values in the pre_get_posts filter?
- How to order separated Custom Post Search results
- Displaying custom taxonomy in the admin list of a custom post type
- search also in taxonomy, tags and custom fields
- How can I run this code once so that my generated post title doesn’t keep changing on publish/update?
- Custom post type search using $_SESSION and pre_get_posts
- How to stick custom post at the top in search results
- Can I search only some of the fields of a custom post type?
- Custom Post Type And “fopen”
- Categories of custom taxonomy don’t show any posts
- Filter custom posts using auto populated dropdown selectors
- Make parts of your wordpress website completely built with data from external APIs?
- How to add a post slug to a url?
- changing meta value and meta key of price field
- How to filter wp_list_categories output with some custom post type meta query?
- How to Filter custom post type by taxonomy?
- Separeting product from post in search result
- Filter term taxonomy metabox in custom post type
- creat filter with wp_query
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- Woocommerce search pagination not working
- WooCommerce Customer Role Delete Custom Post Type
- Including metaboxes from custom post types in global search — continued
- Custom post type not showing in search result
- How can I made custom taxonomies relationship?
- Manage custom post type in woocommerce /my-account/ page
- How to change the post type a theme shows by default?
- filter custom post in rest api with custom function
- Woocommerce custom field search in custom post type [closed]
- What to and how to proceed with CPT to make DB small and efficient?
- Pretty URL for custom search for custom post type
- Filter hierarchical custom post type admin page by parent, and include children & grandchildren
- Sort and filter custom post type posts by custom taxonomy
- Add post location with mile radius allowing search
- Versioned Custom Post Type (Not the same as revisions)
- Include custom post type content in search
- Modifying custom post type created by WooCommerce
- Get post count for search result based on post type
- Hide a widget inside a div on specific type of post
- Auto Complete Search
- Allow add new post access to custom post but not wp post for some role
- Loop filtering Custom Post Types and/or Categories
- Searching Custom Post Types
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- the_content filter on some post types only not working
- Display Woocommerce Orders for specific author [closed]
- Filtering posts list table
- How do i search authors from search form using author’s name
- Custom filter function not working with Custom post type
- Filter Posts from the Main Query
- Remotely search WordPress sites using xml-rpc
- Categories filtering in new post
- How to use manage_$post_type_posts_columns with underscore in post type?
- BBPress Search results in WordPress search
- Limit Search to Post Type With Apostrophe return search not found
- How does the filter post_updated_messages work?
- Set Custom Post Type in Widget Settings for use in Widget
- How to order posts of a custom post type by date DESC in dashboard Admin?
- Displaying and searching Custom Posts
- Search by tag name and category
- Searching Custom Fields
- Advanced search form with filters for custom taxonomies
- dropdowboxes with pre-selected custom fields optios that filters the results according seach needs
- filter search custom field query
- Different results between permalink and query var search
- How to let users choose where to search for posts?
- WordPress Custom Search by post_type
- Include custom taxonomy term in search
- Redirect to another page using contact form 7? [closed]
- How can I add a filter to a particular post format?
- What content types are shown at a search page?
- Can NOT search my custom post type?
- Is there any way to get list of all possible filter hooks for all post types?
- Can I display custom post types in home.php or need page template?
- Sort posts in loop by the WooCommerce Membership of the author
- Search one custom post type ONLY, disable “all posts”
- Create new custom post and post category of same name
- wordpress remove views from action links in a custom post
- Custom post_type search pages
- Pagination Error : Duplicate argument being outputted
- WordPress search and date filter not working with custom post type
- Custom Empty Results page for my Custom Post Type