we are trying to optimize a heavy traffic WP site, and am looking for a way to get the data for these three WP functions with only one query, in order to reduce queries & load on DB server:
$wpid=get_the_ID();
$title=get_the_title($different_post_id);
$perma=get_the_permalink($different_post_id);
Is this possible?
EDIT-- adjusted above example code to correctly indicate that in this case, we're grabbing the title and permalink for a different post_id -vs- the one that's returned by get_the_ID();
we are trying to optimize a heavy traffic WP site, and am looking for a way to get the data for these three WP functions with only one query, in order to reduce queries & load on DB server:
$wpid=get_the_ID();
$title=get_the_title($different_post_id);
$perma=get_the_permalink($different_post_id);
Is this possible?
EDIT-- adjusted above example code to correctly indicate that in this case, we're grabbing the title and permalink for a different post_id -vs- the one that's returned by get_the_ID();
Share Improve this question edited Jun 24, 2019 at 15:32 Linux Pro asked Jun 21, 2019 at 14:12 Linux ProLinux Pro 1464 bronze badges1 Answer
Reset to default 3These functions do not even call the database each time they are run. It just pulls them off the current post object that was returned by the database query that retrieved the posts. There's nothing to optimise here.
get_the_ID()
and get_the_title()
literally just return $post->ID
and $post->post_title
. get_permalink()
is a little bit more complicated, because it needs to do logic to figure out what the URL should be, based on permalink settings etc., but it doesn't require additional database calls.
WordPress is not so poorly optimised that you need to do anything about these functions. If it's how the documentation tells you how to do it, and it's how the default themes work, then it's fine.
If you're concerned about the speed of your site, then install Query Monitor and at least check what queries are actually being made before deciding on a target.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745374396a4624936.html
评论列表(0条)