pre_get_posts
does not explicitely changes the value in the db of posts_per_page
, this value stays constant to the value set in the back end under the readings settings. pre_get_posts
only changes this value before the SQL query is build in WP_Query
right before the main query runs.
If you need to get the exact ( more specific ) amount of posts per page set for a specific page when using pre_get_posts
, access the query vars which will hold the new value set by pre_get_posts
. (NOTE: query_posts
breaks the main query object, so if you use query_posts
somewhere on the page, this will also fail as you will get an incorrect value. This is ONE BIG REASON why you should never ever use query_posts
Here is an answer that explains this in detail.)
Instead of using
get_option( 'posts_per_page' );
use
$wp_query->query_vars['posts_per_page'];
Related Posts:
- WP_Query with “post_title LIKE ‘something%'”?
- How to extend WP_Query to include custom table in query?
- Can wp_query return posts meta in a single request?
- compare meta_query in get_posts arguments
- How to use the_posts_navigation for wp_query and get_posts?
- How to paginate attachments in a secondary query as gallery?
- How do I order pages and categories by ID or name in the same query?
- How to do a query only on a specific admin page?
- WP Cron and wp_insert_post
- How to make an activities stream mixing posts and comments?
- How to adjust found_posts so that it accounts for offset and pagination
- SQL query equivalent to WP User Query
- Function to check if author has posted within the last x days
- Single page theme that uses pages for the content
- Show default content if custom WP_Query has no posts
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- using wp_query to return posts w/ comment count > 0
- Pagination for custom query on single.php
- wp_transients | wp_object_cache VS SESSIONS & Cookies?
- How to hide post content/meta from everyone except the post author and admin
- Remove ellipsis from the excerpt retrieved using get_the_excerpt()
- Too many posts cause slow load when paginating
- WordPress query vars are not added
- When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?
- Formulate a url to show posts with both taxonomy terms
- Alternative to query->set that appends conditions instead of overriding
- Group WP_Query by meta_key date
- Set if condition with wp_nav_menu
- How to reduce the number of queries?
- why update and delete query not worked in custom table?
- get_users is missing or skipping over users in loop
- WordPress Related Post by tags in Single.php
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- Query custom post type by custom taxonomy (category slug)
- WP_Query sorted by custom taxonomy
- problem by deleting new plugin installed inside the WordPress after any heroku app sleeping [closed]
- Use posts_groupby filter with part of string in wp_query?
- Adding multiple meta_key fields as orderby options to a WP Query via a function
- 1/3 of posts different class
- Search for “2nd” also returns “22nd” in wp_query
- Get posts by list of post IDs ordered by those IDs?
- WordPress Blog Posts with Pagination inside a Page/Post
- exclude a post from wp_query loop
- Reset WordPress Post Query to default
- Is_single() conditional tag returns null in query
- Woocommerce – exclude only older out-of-stock items
- Limit home post to 10 without creating pagination?
- Is it possible to query a custom field where the value is between two fields?
- Wildcard search in WP Query
- Get Child Category only
- Order is breaking wp_query
- How to display all posts not in a post_format
- Especific order by Custom Field Values in WP_Query
- How to filter query loop block with a search string from the query parameters
- WP_Query – How to get all posts of specific days of week by custom field date?
- WP_Query returns no posts for category
- Querying a large number of posts including their custom fields data
- Group posts by attachment meta key
- date_query is showing duplicate results
- Post__not_in only removing first 2 pages
- How to query posts for custom post type with featured image for first 2 post?
- Query posts by searching for a string in a meta field
- Added Date Filter To Popular Posts Query
- WP_Query with 2 genres
- Display posts from an array of ID’s
- Date not appearing in custom query
- Custom post type – filter content by custom meta box content
- How can I build a query that returns all attachments of a page and it’s children pages?
- Query ACF relationship field – Comparator IN – Value array
- Use get_cat_ID to retreive multiple category IDs
- How can I modify the query by adding to the existing query?
- WP_Query Regexp whitespace and end of string
- Custom order of posts in wp_query and different taxonomies
- WP_Query paginate with one term per page?
- Update wp_query every week
- wp_insert_post with ACF Fields and WP Meta Query returns no rows until update
- using custom meta user data to run queries in WordPress
- Look for string in posts and postmeta
- Multiple meta_query not working
- Is meta_key used for ordering, filtering, or both?
- Save query in function for custom gallery
- Merge two queries and remove duplicate
- Convert SQL Query to WP_Query
- WordPress wp_query add custom query as field
- Get a page ancestor from a most viewed list
- What argument does my function need to echo get_results() query results
- Custom pagination (Title, date and teaser)
- Using custom field as ‘orderby’ value causing post grouping by publish date
- Sorting Posts with meta value not working
- Display posts from catagories
- Add pagination to table generated by wp_query
- Fire query on ajax post url page
- using next-page and previous page inside a wp_query
- What is wrong with this pagination code?
- tax_query not working properly with get_posts
- how to add limit records in wordpress query
- query only direct child and sub-terms of a current term archive
- restrict posts per page
- WP_Query by meta key not returning any posts
- Why am I getting no results of a query placed after another query?