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
- Best way of passing PHP variable between partials?
- Use author author display name in permalink structure for pages and posts
- Import WordPress XML File from Within Functions.php
- Difference between the_content() and get_post()?
- Automatically set the featured image
- How to target specific wp_nav_menu in function?
- Is it possible to use a forgot password url filter?
- remove the wrapping of text widget or
- how to make wordpress not to look for themes
- Displaying Saved Meta Box Data in Drop Down with selected()
- Conditional Page Template not working
- How to override enqueued styles using a child theme
- changing function wp_register
- What is user_trailingslashit() for?
- How to include all files within a folder to functions.php?
- How to make applyFilters function return false via functions.php
- How to call custom function from functions.php in site-wide template files?
- Load .txt file for login_message in wp-login.php
- Calling a function from anywhere, used in different places
- How do I redirect all 404 error url to Subcategory url
- Php function 301 redirect
- Function only on a specific page
- get_next_posts_link not working without parameter max_num_pages
- create filter in functions.php
- Logout Shortcode URL
- Add Custom Background Properties to Customizer
- What is the correct way of updating wordpress options
- Multisite 404 on pages – rewrite error breaks database
- Make wp_link_pages() suitable for Twitter Bootstrap markup
- I can’t seem to install Font Awesome locally [closed]
- Prevent custom field from being updated after first publish
- laoding bloginfo url in function array?
- How to edit classes in body tag?
- Add a field into a shortcode of an extension
- Need a method to prevent WP from adding in between my shortcodes
- How to edit/replace Parent functions.php function in Child Theme to add “Walker” class
- Load scripts for do_shortcode( ‘ [ my_shortcode ] ‘ )
- How to modify get_the_excerpt() when post-format equals ‘quote’?
- New checkbox in custom widget isn’t saving data
- Post to category based on email domain, for a post-by-email plugin
- struggling with syntax for the_post_thumbnail();
- Echo youtube code from url or shortcode
- Woocommerce Default sorting product by product type
- Displaying registered sidebar after post content
- Malfunction via Safari [closed]
- Does hook have an effect on increasing the page load?
- Adding a schema code to one specific page using functions.php file
- Multiples functions on customize_register?
- Can I call a functions.php file from a different URL?
- Javascript file loads only on homepage, not on other pages (404 not found error)
- price of product can’t return when get data of product in functions.php
- Prevent function from triggering on current page
- How would I correctly implement a new if statement in a child functions file?
- How To Show Shortcodes In WordPress Custom Fields?
- Language Switch Function
- How to debug function file causing white screen
- Post date on Custom field
- Fatal error: Call to undefined function add_action() – an untouched problem
- Author info does not show up when author has no posts
- Load CSS conditional on custom field is present
- Modify sub_menu function to show pages below a specifically set page
- Add custom class to all URLs on entire site
- Functions.php in child theme that loads CSS file breaks website
- Unregistering custom tinymce plugin?
- Combining wp_current_user() and a variable
- Init hook for header send
- site_url is not honoring scheme
- Problem with removing characters “<” – WpAllImport
- Function attached to cron job not running but will run if called manually
- How to use a function inside of a function, or rewrite this code to work: