This should not break pagination:
add_filter('pre_get_posts', 'optimized_get_posts', 100);
function optimized_get_posts() {
global $wp_query, $wpdb;
$wp_query->query_vars['no_found_rows'] = 1;
$wp_query->found_posts = $wpdb->get_var( "SELECT COUNT(*) FROM wp_posts WHERE 1=1 AND wp_posts.post_type="post" AND (wp_posts.post_status="publish" OR wp_posts.post_status="private")" );
$wp_query->found_posts = apply_filters_ref_array( 'found_posts', array( $wp_query->found_posts, &$wp_query ) );
if($wp_query->query_vars['posts_per_page'] <= 0) {
$wp_query->max_num_pages = 0;
} else {
$wp_query->max_num_pages = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
}
return $wp_query;
}
Related Posts:
- WordPress Custom Query
- get_post_meta causes database queries
- Custom MySQL Query with logic
- How can i get count from query post
- Is there a way to exclude the content from the post variable to save on RAM usage?
- Display/query post formats
- How to query post by user role?
- Ensuring sticky posts are retrieved first (without using two queries)?
- Determine if more posts are available than was asked for in `query_posts()`?
- query_posts() in function makes global $wp_query out of sync?
- My WordPress site always displays a cached version of its homepage
- Using dynamic conditions in ‘posts_where’ filter
- Help altering a query to exclude all but standard post format
- List users with the most total posts view
- How to limit search to first letter of title?
- Post Title displaying but not in the wrapped HTML I need
- How to ensure that is_search() return false after query_posts
- Inserting Post Using wp_insert_post. How to Fill Yoast Plugin SEO Fields
- Why is that gdsr_sort=thumbs (GD start rating plugin) only works with query_posts and not with WP_Query?
- Query_posts $query_string
- How to order posts by slug using query_posts/ Wp_query
- Query 1 taxonomy term, exclude another
- Order by meta_key with two meta_queries
- Pagination on custom query
- Search stores (custom postcode field) within 5, 10, 15 miles of user inputted postcode.. Code modification
- Ordering terms before displaying posts
- What is the difference between “manage_{$post_type}_posts_columns” and “manage_edit-{$post_type}_columns”?
- Sort Posts by Multiple Meta Values [duplicate]
- Querying posts with meta value that begins with a certain pattern
- How to show only today’s post?
- Insert all post IDs in new database table
- use query_posts to return a post OR a page by ID
- Adding Variables to post query
- Unable To Get Published posts using query_posts
- Read More is not working in query posts
- query_posts for child pages
- How to reverse the order of WordPress blog posts?
- orderby:date not working
- query_posts() ALWAYS displays something?
- Trouble with get_next_post() get_previous_post() returning null
- Single meta key with multiple meta value in like comparison
- How can I revert to showing cached pages when no database connection is available? [closed]
- Handling large N data in WordPress
- Possible to display posts containing a short code ?
- How to run a SQL Query for character in Post Titles
- Authors List page : how to exclude posts from certain category
- Query a WordPress page by its title (which has a parent page)
- Sorting a query Field by date
- Site not responding error – taking long to load [closed]
- Order posts alphabetically: how to set order=asc in mysql query?
- post_parent array doesn’t work
- number of posts per page + random + exclude categories
- How effective are cacheing plugins for dynamic pages?
- How to Query Post
- query_post and wpdb returning different results
- Exclude current sticky post
- How to place an image after Nth number of posts in query_posts
- Related Posts: Notice: Undefined offset: 0
- When to use WordPress loop or Foreach loop?
- Can’t get pagination to work for sticky posts only
- WordPress Custom Query to get Most Commented Posts in the Past 7 Days
- show x number of posts from y category on homepage
- How to Show Comment Count on Related Posts?
- How can I show only 5 posts from the relationship?
- Should I store critical css in the database or in my theme’s filesystem?
- How to get Caching Plug-ins to work on localhost with HTTPS?
- Make query_post category name dynamic
- How can I list posts with different formats depending on order?
- query_posts orderby postmeta [closed]
- WordPress Query based on random taxonomy
- Displaying and Querying Posts with Featured image
- Restrict query_posts by Date?
- How to solve this without flushing the rewrite rules for each post query the visitor triggers?
- View Achive with Category Filter, but Page per post not working
- grab neighboring content in a query
- Notting but the latest post content keeps on being loaded
- query_posts doesnt show pages with given ID when post_type => page
- Query add html after set amount of posts?
- Custom loop off by one post
- Is there any way of only retrieving posts with one or more thumbs up (GD star rating plugin)?
- How to setup blog page to render blog posts minus afew categories
- How to cache a custom API call?
- Ordering of posts, 2020 Year showing as next event when should be last
- How to put orderby on a custom field in query_posts
- How to disable cache for the content returned by a shortcode
- wp_remote_post and form post
- Filter posts by current date ( WP Post Carousel )
- Completely reload style.css
- How to display most popular post by views count in WordPress?
- Sort Posts By Custom Field Date
- Custom query posts error
- wp_query by last month + sort posts
- Post Filter clearing on pagination $_post
- query multiple posts by id using a string parameter, not array()
- query_posts – slightly more advanced query
- Query posts in a category and include only one post per author?
- Query Posts Creates 404 Error
- Achieving pagination with `query_posts`
- query_posts works while get_posts doesn’t
- Assign a tag to custom post type using a query