You can set the posts_per_page with pre_get_posts action like this:
add_action( 'pre_get_posts', 'my_set_posts_per_page' );
function my_set_posts_per_page( $query ){
if ( is_admin() ){
return;
}
//Check if this is a search
if ( isset( $query->query['s'] ) ) {
$query->set( 'posts_per_page', -1 );
}
}
Related Posts:
- Find out total number of pages in global query on archive page?
- Resetting post data to previous loop in nested loops
- Order by multiple meta key and meta value [closed]
- Is it possible to completely stop WP_Query retrieving posts?
- Order by optional meta key?
- Pagination returns 404 after page 20
- Make a WP Query search match exactly the search term
- Make loop display posts by alphabetical order
- WP_query to get the first two latest posts, then another loop to get the next three
- Why is WP_Query not working with category_name?
- Displaying several specific pages using WP_Query()
- WP-CLI How to generate a list of posts with corresponding meta values
- Query to return maximum of one post per author
- Get attachment by slug
- Warning: urlencode() expects parameter 1 to be string, array given
- Group posts by custom field
- How to get the posts published in last two days using WP_Query?
- getting posts and number by specific meta value in multiple meta
- How to query using a combination of custom_field values?
- All sticky posts are returned in custom query
- Get attached media only
- Can not switch the queried post in pre_get_posts hook
- how to fire join query with post_meta
- Show one post per author and limit query to 8 posts
- Why use JSON API to display recent posts?
- SELECT * FROM $wpdb->posts WHERE ID > 160
- How to show the posts of some category first, and then all other
- Pagination problem after WP_Query with tag filtering
- Custom Loop in Page Admin Causing Other Fields to Fail
- Pagination stops at page 6
- How to limit total number of posts in wp query loop?
- Get list of terms that have posts in another term
- WP_Query with Metavalue
- Custom query for sidebar isn’t returning results
- How to vary post loop results layout and resume?
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- Adding an array from a query string to a WP meta_query
- WordPress add_rewrite_rule() cannot visit lower url levels
- Get a post from other loop each n-posts in the main loop
- WP_Query() and get_posts() can’t handle over a thousand posts?
- Sort by price woocommerce by ID post_meta
- Using Advanced Custom Field for file upload, how do I load the file url
- Retrieve posts using thumbnail id as meta key
- Which is faster wpdb & get_row or wp_query & ge_post_meta?
- Modify Search Query if original Query gave no results
- How to cache wp_query with pagination using transients?
- Problem with WP_query
- Why is WP_Query not displaying expected data?
- Filter post query to only show direct children of category
- Highlight current post title on a page
- Why won’t draft listings appear for non-admins?
- My WP_Query didn’t work after upgrading to WordPress 3.2
- meta queries do ‘either/or’ checks
- search serialised meta_value for date value?
- has_excerpt() not working inside wp_query
- Apply query arguments after the nth post
- How to properly use AND / OR in custom search
- Get post and its children with WP_Query
- Get every post with value in meta key
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- Searching by title, content and custom taxonomy
- Storing an array of objects related to each user
- How to get posts by category and by choosing a taxonomy term?
- Paging + WP Query
- Getting the permalink to the latest post from a category
- How to restrict search on a certain page to only return results against custom taxonomies?
- Paginate pages with dynamic query
- WP_Query loop doen’t work with my custom taxonomy
- Deleting terms from the WordPress wp terms table
- In a WP_Query can I force the results’ is_singular() to be set to false?
- My combination of ‘post_type’ and ‘tax_query’ not working?
- Order (by ASC) posts with meta_key so posts without values are last
- Query pages created by deleted users
- Get posts that match defined arrays of tags
- WordPress live search and filter
- Why can my filter query SOME metadata but not other metadata?
- The query show user list orderby count published posts in last month
- WordPress – Form does not filter the results of taxonomies
- How can I use WP_Query to sort ‘event’ custom post type by date?
- Sorting Posts by Taxonomy thats not within the query’s $args
- Order Posts By Custom Field That is an array of objects
- Custom query: post__in parameter causes query to be empty
- How to use wp_query in different column in single loop
- Paginated Post List on Front Page
- Show subscriber id in loop
- modifying the loop multiple times with arguments passed through ajax to wp_query
- WP_Query – show posts where meta value and user_email match
- WP_Query causing links to not work
- WP_Query using meta_query with LIKE doesn’t return what it should
- Website goes slow down after importing long database
- How to organize a WP_Query’s list of posts by category and display category title?
- How to Query Updated Post in WordPress
- wordpress nested loop
- Including ‘cat’ => $cat breaks meta_query
- Query_vars not working for me
- Query posts only shows 1
- First post outside of loop, homepage only?
- Extend search query to search meta keys values based on search string
- AJAX multiple search boxes not merging with array merge
- Display Featured image from custom post type category (custom taxonomy) wise