If I understand you, what you are doing is wildly complicated. All you should need is a simple pre_get_posts
filter:
add_filter( 'pre_get_posts', 'modified_pre_get_posts' );
function modified_pre_get_posts( $query ) {
if ( $query->is_search() ) {
$query->set( 'post_type', 'product' );
}
return $query;
}
Plus your filter that adds DISTINCT
.
post_type
is a query parameter rolled into Core. Passing an URL such as localhost/wp/?s=D34&post_type=product
should by default limit your queries to the single named post type. You shouldn’t have to do anything special to make that work. Your filter may in fact be causing trouble.
Related Posts:
- How do I change the core post search algorithm? Where is it found/constructed?
- Target only single product page
- Woocommerce – custom post type of checkout page
- Including categories in search results
- Search Custom Post Type Pages and Custom Fields in 2 Dropdowns?
- How do I create a link that will always show the latest post?
- Display all search results
- What is the difference between “post” and “page” in WordPress?
- Create custom page in WooCommerce
- WooCommerce – Create Products Programatically [closed]
- Search posts by post author name
- Search not working with title and content
- how to hide specific post from google search
- How to search only by post title and category?
- Search widget breaks when using multiple loops?
- Pagination not working on custom query
- How can I get all posts data from within a paginated search result?
- Search query – exact post title match
- pagination hook doesn’t work with search results
- Search for posts based on their url in the admin?
- wp_query ‘s’ parameter does not work with custom post type
- How to Use PHP Code In-Page?
- Differentiate between posts and pages in search results
- Understand post type
- Count search results in heading
- Private Posts/Pages & Search
- Display number of posts via adress bar?
- Tags to Post-ID mysql query. Tag Search
- View the number of entries recorded per day
- How to change wordpress dates to native language (even if the languge not available i wordpress)
- Display featured products by category
- Insert woocommerce products programmatically with featured image and gallery
- Problem with adding programmatically woocommerce product post into category
- How to filter my search in post if contains a word in title, content or excerpt?
- Search results posts_orderby and ID
- Skip in WordPress Post ID’s, can this cause issues?
- Posts and Attachments with “Published” status in Search
- how to get random post id by using post type
- Show posts count for Categories and Tags in wp_nav_menu
- why there are so many posts whoes post_type is revision? will these records waste too much database space?
- How to add add more properties to WP_Post object in search results loop
- Post type no single page
- Total number of posts in query (category/tag/author/search results/main page…)
- See if a post has a specified tag
- Is it possible to automatically publish a post once a woo-commerce product is published?
- Restore woocommerce orders
- Why does WordPress search returns same number of results for every search query?
- Hide parts of the post content after typing it’s name or searching it by category
- search content of pages and list in wp-admin
- How to exclude the word “class” from being matched in search?
- Will multiple category descriptions effect my search engine optimization?
- What would causes search to return incorrect results?
- I want to add another search box on posts page in dashboard
- Get category slug of the Parent category of a Product
- Showing Posts if non are found
- search form for custom fields
- How to show posts in grid style on search result page?
- Search results with pagination not working
- How to fetch courses in all languages in WordPress?
- How to show only homepage in google results instead of privacy, contact pages
- Redirecting wordpress search query to archive page
- How to search through “post title” and “tags” using WP_Query?
- How to create custom search form function including post “tags”
- Remove pagination if search returns empty
- How to distinguish pages created by woocommerce?
- Disaply products from category
- How do i search post by jquery datepicker?
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- Show code only on WooCommerce Pages
- show only one category and filter by tag
- On WordPress Search, how to search post from Author meta also
- How to hide meta from search result only on pages?
- Find post tags words in post content and link them to tag URLs
- Custom author search
- WordPress search for specific Post Type
- Display result of custom form
- Customize search results to include custom posts and display in a specific template page
- How can i retrive the movies, trailers, news in a single page using search
- Custom Post Title as search term
- Related posts by searching post tags of single post as terms
- Taxonomy Category category.php not working
- How can I get the first post THIS SAME CATEGORY?
- Wp_query WooCommerce products
- How do i retrive a post from a custom post type
- Search doesn’t display posts with images
- Showing random content / pictures from earlier posts in a sticky post?
- Function to show random posts from a category
- wp query with dynamic taxonomies and terms?
- How can I hide the sidebar from a specific post?
- How can you change all past posts’ images to link to none instead of the image file?
- Apostrophe in a possessive appears as an open-single-smart-quote instead of a closed one
- Only display sticky post or latest post in custom loop
- Grid post page on WordPress with Bootstrap, the_excerpt(); Problem
- How can I globally italicize list of texts in the UI database or Posts? [closed]
- get_next_post() not working with future post status
- Show post published live
- Need help writing loop to display posts by categories in separate divs
- Where should get_post_meta() go to get $post->ID get_post_meta() is empty and $post->ID & get_the_id() are working
- How to make posts appear under pages
- Default post type doesn’t display in url