I recently had a similar problem and it had something to do with the query’s posts_per_page
parameter. Try setting it explicitly, like so:
function custom_search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('posts_per_page', 10 ); // Try setting it to the number you've set in the WordPress admin (Settings > Reading).
$query->set('post_type', array('post','product'));
}
}
}
add_action('pre_get_posts','custom_search_filter');
Hope this helps!
Related Posts:
- Exclude a term of a taxonomy with a custom post type in a search
- Set meta_query only for specific post type
- Blank search results on custom search
- Custom Search Template for Custom Post Types
- Include custom taxonomy term in search
- Searching multiple custom post types and pages
- AJAX search on post pages by custom post type
- How can I change the admin search posts fields?
- How to make a WP_Query search with custom post types?
- Development of a WordPress Search Plugin – Best Practices
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- Simple way to search custom-post types only
- Pushing a custom post type to the top of the search results
- Returning search results by relevance, including Custom Post Types
- How to replicate some of Drupal Views functionality in WordPress?
- Exclude from search all custom posts which are NOT in a taxonomy term
- Search everything (posts, pages, tags, cpt, meta)
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- filter search result with custom post type meta key
- Custom search for custom post type, custom meta and search fields
- Search Post Title Only [duplicate]
- Query for posts from any post type but only add instock products
- WooCommerce – Show orders for a specific product ? [closed]
- custom search result page
- get_terms won’t display product_cat or any other custom taxonomies when specified
- Customize Search Results for Custom Post Type
- multiple search forms and search results
- Search Custom Post Type Custom Fields
- Custom Fields vs Separate Table
- How to search map address in custom post type?
- Custom Search for Drafts in Custom Post Type
- WooCommerce product search titles only
- custom post type Search returns No Results in admin panel
- Get post from custom post type order by two taxonomies
- Search Custom Post Type & Taxonomies
- Multiple meta_values in the pre_get_posts filter?
- How to order separated Custom Post Search results
- Custom post type search using $_SESSION and pre_get_posts
- How to stick custom post at the top in search results
- filter custom post type by meta key in dashboard
- Can I search only some of the fields of a custom post type?
- Make parts of your wordpress website completely built with data from external APIs?
- Custom post type not showing in search result
- Manage custom post type in woocommerce /my-account/ page
- What to and how to proceed with CPT to make DB small and efficient?
- Hide a widget inside a div on specific type of post
- Auto Complete Search
- Display Woocommerce Orders for specific author [closed]
- Remotely search WordPress sites using xml-rpc
- Limit Search to Post Type With Apostrophe return search not found
- Search by tag name and category
- Advanced search form with filters for custom taxonomies
- filter search custom field query
- Different results between permalink and query var search
- WordPress Custom Search by post_type
- Include custom taxonomy term in search
- What content types are shown at a search page?
- Search one custom post type ONLY, disable “all posts”
- search custom post type by custom fields on front end
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- Custom Search | check multiple meta_value for search value
- Hide custom post type from search based on custom taxonomy
- Get all post from a post type
- Pagination on search results page
- Best way to create a search for custom post type by custom field values
- Get Terms from Custom Taxonomy and Current Post
- Limit search field to just search a custom post type with custom fields
- Redirecting search to specific templates with $_GET[“post_type”]
- Search custom type post
- How to display related posts using the same taxonomy for custom types (WordPress, Pods, Woo)
- How to display custom field in product description?
- What’s the best way to do this: inquiry/ticket system?
- Creating a custom WP query for a Custom Post Type
- In the php, how can I have a category of a custom post type display?
- Search Function not searching correct custom_post_type even though post_type is defined in search args
- Change display of product price on product show page only
- WP_List_Table Inside Metabox Not Working on Clicking Search Button
- edit.php all post not working
- search results to show individual ACF fields from inside custom posts
- post_type incorrect for custom post type
- Live search by custom tag
- how to create custom taxonomy drop downs for parents and child
- WooThemes – Vendors / Bookings – Allow Vendors to manage resources
- woocommerce post_type conflict with existing post type
- CPT or Custom Table for Repository of Serial Numbers
- WP_Query with custom post type search showing all results every time
- Extensive search filtering and results->PDF in the front-end
- 404 error Custom search results page for custom post types with friendly URL
- Multiple search template with separate stylesheets
- Advanced search form with filters for custom taxonomies and custom fields
- Searching for a single custom post type, buddypress
- How do I do this?: If custom post type exists, echo it, else do not
- WordPress search results
- How to manage a bookstore
- Drop Down Filter with CPT as Options for Search Form
- Create a WordPress Database query to find users who purchased specific product through WooCommerce [closed]
- Searching Custom Posts content with JQuery
- WordPress search results grouped by post type
- Why custom search engine only searches in post titles of custom posts?
- Meta_query question