[Resolved] Main $wp_query returning WAY too many posts.
I can usually troubleshoot issues pretty easily, but this one has me stumped.
I’m working on an old site, 5 years of content, over 4000 posts, loads of comments and images, etc. It’s completely up to date, no strange plugins active, and just to make sure it wasn’t a theme issue, I did my testing in TwentyTwelve.
The homepage has been running quite slow lately, so I did some debugging.
First, the relevant debug bar query results:
SELECT SQL_CALC_FOUND_ROWS w1L7f03Z_posts.ID FROM w1L7f03Z_posts WHERE 1=1 AND w1L7f03Z_posts.post_type = 'post' AND (w1L7f03Z_posts.post_status = 'publish' OR w1L7f03Z_posts.post_status = 'private') ORDER BY w1L7f03Z_posts.post_date DESC LIMIT 0, 12 SELECT FOUND_ROWS()
Nothing too strange here. I have 12 selected as my posts per page in Reading settings.
But, when I go to load the page, it takes FOREVER … like it’s literally trying to loop through and display every post in the database. Honestly, I never let it finish, but I suspect this is exactly what’s happening … it is trying to loop through all 4000+ posts.
So, before the loop in index.php (twentytwelve), I pasted this in:
<?php global $wp_query; echo 'Debugging. Nothing to see here.<br /><br />'; echo '$wp_query = ' . count( $wp_query->posts ); echo '</div></div>'; wp_footer(); exit; ?>
This is how I got my debug bar results.
Sure enough, the
$wp_query->postsresult is 4337.
Does anyone have any idea what could be causing this? I can provide other info, if it will help.
FWIW, I disabled all plugins and it’s still happening, so I don’t think I can blame a theme or plugin.
- The topic ‘[Resolved] Main $wp_query returning WAY too many posts.’ is closed to new replies.