This code will only search form woocommerce products. If you want to show any other search result from another post type you can do by simply change post type slug 'product' with you own post type slug
add_action( 'pre_get_posts', 'wpse223576_search_woocommerce_only' );
function wpse223576_search_woocommerce_only( $query ) {
if( ! is_admin() && is_search() && $query->is_main_query() ) {
$query->set( 'post_type', 'product' );
}
}
Related Posts:
- How to redirect to post if search results only returns one post
- Possible to search by author name with default WordPress search function?
- paginate_links() don’t properly work in search.php?
- Filter the query ONLY for the search results page
- Extending the site search to include a single custom field
- Modify search function in WordPress (TwentyTwelve)
- How to customize search result page title?
- Display WordPress Search
- Search user metadata with checkboxes via ajax (almost working)
- Searching for content post
- changing behaviour of get_search_form
- Search filter by Post title OR Meta Title Value [duplicate]
- Using wp_redirect and .htaccess to re-route searches (and pass along the remaining GET vars)
- paginate_links() don’t properly work in search.php?
- Include the post type before the title of search results
- How to rewrite wordpress search to work on specific category
- two search forms on the same page
- search form leads to 404
- Custom function for search form
- WordPress: Highlight search result exact matches
- More than one search results page template for two searches on site
- How do i create a search option for pdf’s only
- Form output outside of container
- Limit Number of Posts on Blog Category Page Throwing 404 Error on Paginated Pages
- us states dropdown function and echo in theme template files
- Pagination in Search result
- Make WordPress search for only this tags or exclude certain tags from search [duplicate]
- child_of not working while searching
- Search Woocommerce product titles only
- Custom Post Type Search
- How to influence the information displayed on widget inside wp-admin
- Remove Container Element From wp_nav_menu() Markup
- How can I get $id variable in widget’s form function?
- difference between add_object_page and add_menu_page
- Make WordPress size and name images for Retina.js
- Pinterest Integration Using functions.php
- Adding WooCommerce to a Custom Theme – not working [closed]
- Changing itemprop from logo to image on custom logo?
- wp_get_post_terms() returns WP_Error in functions.php but in template it works
- Move jQuery and Migrate to footer?
- Change Rating range in Link Manager
- Count the number of times the search form template gets included on a page
- function to erase swear words
- str_replace function in theme
- Function call via ajax – can’t figure it out?
- How to add nav menu items to a specific position within a menu
- woocommerce: change default setting > is_sold_individualy function
- WordPress Menuing Question :focus
- call of javascript function to external url always blocked by cors
- wp-comment author- url +, email filter hook
- What WordPress function to use to get meta value by using meta keys?
- how can I just add to parent theme function(s) instead of redeclaring whole the function
- Create a custom taxonomy that will be used to create and filter markers in a Google Map
- How to create an onclick event on an image in a post?
- using jQuery on only one page
- Setting a default text for excerpts of a particular category
- How can I use Woocommerce $product->get_attribute in functions.php? (if at all)
- How to set default post editor based on role?
- How to display the_archive_title() and the_archive_description() – “weird” interaction
- Remove Jetpack infinite-wrap
- Create a Woocommerce product widget with category filter
- Using two loops in one WordPress template
- Multiple navigation menu in same location
- Function to echo (or display?) wordpress tags in the head section
- is_home() not working in functions.php file
- Filepath to Chosen for “Home Page” option – Which function?
- Check if a different page has any attached images
- Custom route and extract data from slashes and parameter
- Customise the WordPress gallery html layout
- Change class woocommerce on function.php
- Google Analytics – add script to functions.php
- Function to function shortcode help [closed]
- I’m creating a online store for my website, my aim is to add description to products in home page only how can i achieve it?
- modifying every other element’s class inside while loop
- Adding Custom Body Class for Page: Shop
- Menu and category highlighting for a single post
- “Conditional query tags do not work before the query is run. Before > then, they always return false. “
- Change ‘Categories’ to ‘Topics’
- Code I am placing in the wp_footer is going outside the entire HTML frame!
- How to assign results to variables?
- Restoring pages in wordpress
- Redirect after login to current URL
- Different body image backgrounds on different pages, posts and categories
- Hide certain post types from editors
- Language switcher for subdomains
- Function to draw random image from specified category destroys site logic – why?
- Add Function For Instances of Custom Text in Multiple Category IDs to display in post content
- Move captions under gallery images in twenty fourteen theme
- How to add a class name to the ancestor of a post?
- is_user_logged_in() isn’t working
- Retrive post by tags PHP code
- Sorting date results from a query
- Add custom css to theme
- Why don’t ‘wp_nav_menu’ CSS classes work until a menu is created?
- User’s Comments Number: Storing it in a meta field for different uses
- Show one post per author and order by custom field
- Text before price on WooCom
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- Change Post status based on custom field date +1 day
- How to store page-{id}.php templates in custom folder