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
- single-{$post_type}-{slug}.php for custom post types
- How to make a WP_Query search with custom post types?
- WordPress post sorting with AJAX
- Why have my custom post type searches stopped working after changing URLs / updating WordPress?
- Search that will look in custom field, post title and post content
- How to correctly get post type in a the_title filter
- How to add a CSS class to every image in a Custom Post Type
- Best way to filter featured image text for a custom post type?
- Returning search results by relevance, including Custom Post Types
- How to replicate some of Drupal Views functionality in WordPress?
- Seperating Custom Post Search Results
- Exclude from search all custom posts which are NOT in a taxonomy term
- post_type_link filter causes 404 on the CPT page it’s used on
- Debug output during filter execution doesn’t work
- Unable to filter on field on edit.php page
- Help with issues on “Adding a Taxonomy Filter to Admin List for a Custom Post Type?”
- No results searching custom post type in admin panel
- Adding posts of custom type into the main feed
- Used with meta_query in query_posts works slowly
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- error in Advanced Search Form for Custom Post Types in WordPress array_key_exists() expects parameter 2to be array, string given
- Custom Taxonomy breaking pages permalinks
- How do I set the link in the Custom Post Type admin menu?
- Search Custom Post Type Custom Fields
- Problem adding column to WC Subscription [closed]
- Keyword search limited to specific post type filtered by multiple custom taxonomies?
- Pre_get_posts filter overwrites all search functionality
- Custom query to filter posts that have current post as a taxonomy [closed]
- I did group my search results by post type, but how can i give each of them its own order?
- Append date to custom post type url slug
- custom post type Search returns No Results in admin panel
- Genesis filterable portfolio isotope [closed]
- Search Custom Post Type & Taxonomies
- Categories of custom taxonomy don’t show any posts
- How to add a post slug to a url?
- changing meta value and meta key of price field
- Pretty URL for custom search for custom post type
- Add post location with mile radius allowing search
- Hide a widget inside a div on specific type of post
- Allow add new post access to custom post but not wp post for some role
- filter search custom field query
- Include custom taxonomy term in search
- Create new custom post and post category of same name
- Add custom attributes to a post
- Custom Taxonomy Search result page
- How do I add custom HTML to the content of an archive page’s posts?
- Only show posts with a specific term of an associated taxonomy in a custom post type archive
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- Copy order items with metadata between orders – Woocommerce
- Hide custom post type from search based on custom taxonomy
- Update Post Status On Woocommerce Payment Complete
- Pagination on search results page
- Change permalink for custom_post_type using custom_post_meta (woocommerce)
- Best way to create a search for custom post type by custom field values
- Modifying WP_Title For Custom Post Type
- Multi Parameter search with custom post type category and tag
- How to Implement Search Functionality?
- How to have multiple search result pages in wordpress with taxonomy terms listed
- custom filtering admin columns
- Ajax Post Filter | Split Taxonomy Into minPrice & maxPrice
- Query filter by value in meta_value array
- Display category filters for custom post type when category is shared by multiple post types
- What’s the best way to do this: inquiry/ticket system?
- ‘Simple’ Reservation System
- Create Post Types from a XML url (Real Estate website)
- Post Click Redirect to Custom URL instead of Single Post Page
- Custom Post type doesn’t appear in search results
- How to show link to product in custom fields?
- add action save post type and update post meta woocommerce
- Keep br tags from stripping
- Filter Content on all Post Types
- WP_Query with custom post type search showing all results every time
- Search form to find custom meta box generated data
- Sorting on Taxonomy in archive page
- multiple custom post type category selection search
- Archive custom template from search
- Customising wordpress search and using $_GET[“s”]
- search this custom post type
- WP_Query wooCommerce category
- WooCommerce – Complete Order when an action occurs
- How to manage a bookstore
- Rewrite a filter as shortcode (or something like that) to use anywhere in CPT
- add_filter > posts_where works partially
- Simple Share Buttons Add Plugin and Custom Post Type
- When Attempting to Filter Plugin Generated Content Using Filter post_type_link, Permalinks Are Not Modified
- Change CPT Edit Target Link for Admin List
- Group search results by post type, but having a unique heading for each section?
- Add Custom Taxonomy Terms as CSS Classes for CPT Posts in an Elementor Loop Item Template