[wp-trac] [WordPress Trac] #18822: get_permalink() produces an add. DB request without $post->filter
WordPress Trac
wp-trac at lists.automattic.com
Fri Sep 30 12:36:35 UTC 2011
#18822: get_permalink() produces an add. DB request without $post->filter
-------------------------+------------------------------
Reporter: F J Kaiser | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.2.1
Severity: major | Resolution:
Keywords: needs-patch |
-------------------------+------------------------------
Comment (by duck_):
For the reasoning behind this code see #8526 and [10213]. "Don't cache
filtered post objects. Set filter when getting sample permalink."
Check get_post() and you'll see that that function doesn't always produce
an additional query. For example:
{{{
$posts = get_posts();
foreach ( $posts as $post )
var_dump( get_permalink( $post->ID ) );
}}}
will not cause extra queries as all those posts are cached. You can also
pass the whole $post object to get_permalink for no extra queries as
get_post() accepts an object. In fact get_post() will only perform a query
if you pass an object when the object has the filter property set ''and''
that post ID isn't already cached.
It seems to me that you must be doing something like direct DB queries to
get post IDs and then using those to get permalinks. However you're doing
it you're not getting posts added to the cache when retrieving them to
pass to get_permalink().
--
Ticket URL: <http://core.trac.wordpress.org/ticket/18822#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list