[wp-hackers] get_post() not fetching from post cache after update_post_caches()
William Canino
william.canino at googlemail.com
Sun Oct 4 18:04:52 UTC 2009
Hello all,
Regarding
> $my_query = new WP_Query(array('post__in' => array([very long array of post IDs])));
> update_post_caches($my_query->posts);
> 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
difference.
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?
W
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.
>
> -Otto
> Sent from Memphis, TN, United States
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list