[wp-trac] [WordPress Trac] #27572: get_post_format_link and db queries
WordPress Trac
noreply at wordpress.org
Fri Mar 28 17:02:24 UTC 2014
#27572: get_post_format_link and db queries
--------------------------+-----------------------------
Reporter: afercia | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Post Formats | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
many themes, including Twenty Fourteen, make use of get_post_format_link()
to display a link to a post format index (e.g. /type/video/)
get_post_format_link() makes use of get_term_by() which, as far as I see,
always hits the database to get the post_format term object, then it
passes that term object to get_term_link().
When inside the loop, you likely want to display a link to the post format
index *of the current post*, no need to pass a $format string and the
post_format term object is already cached and available in
$wp_object_cache, so why hit the database?
Imagine an archive page where you display 10 posts and none of them is a
"standard" post: you get 10 extra (useless) queries (tested on Twenty
Fourteen).
IMHO the only use case for get_post_format_link is when you're *outside*
the loop, so you pass the post format slug and you get your link at a cost
of 1 additional query.
But when inside the loop, it would be great to save some queries.
If it sounds sensible for you, I would greatly appreciate your feedback,
didn't attach a patch because I don't know if you would prefer to refactor
get_post_format_link() trying to keep backwards compatibility or build a
new function and encourage to use that instead.
Just as an example, you may want to have a look at the attached new
function, largely based on the way get_post_format() gets what it needs
from the cache.
Thx,
Andrea
--
Ticket URL: <https://core.trac.wordpress.org/ticket/27572>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list