[wp-hackers] get_post() not fetching from post cache after update_post_caches()
william.canino at googlemail.com
Sun Oct 4 18:04:52 UTC 2009
> $my_query = new WP_Query(array('post__in' => array([very long array of post IDs])));
> echo $get_permalink(1);
> echo $get_the_title(2);
> Do you know why WordPress is still making SQL
> queries on lines 3 and 4? Shouldn't they be already in
> the object cache?
I found the answer ... and subsequently found an irregularity in the
WordPress core. I don't know if I should call it a bug.
get_posts is automatically adding "LIMIT 0, 6" to the SQL statement. 6
is the number of posts per page set in the blog's Reading settings.
That's why posts 1 and 2 are not in the object cache. Furthermore,
adding either of the following
'numberposts' => -1 // as per Codex
'nopaging' => true // as per Codex
to the call, such as, $my_query = new WP_Query(array('post__in' =>
[very long array of post IDs], 'nopaging' => true)); makes no
I opened WordPress's query.php and examined it, and found what I had to use:
new WP_Query(array('post__in' => [very long array of post IDs],
'posts_per_page' => 100000));
or some high number. This is the solution.
Moral of the Story: If one uses WP_Query for one's ends, he must set
all the parameters he needs so that the custom WP_Query doesn't use
the blog's settings.
Is this an irregularity or is this a bug?
2009/10/2 Otto <otto at ottodestruct.com>:
> That's fine, but it still doesn't show the actual contents of the
> cache. You're going to have to dump the cache before and after the
> get_the_title call to see why it's missing.
> Sent from Memphis, TN, United States
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers