performance - get_the_id, get_the_permalink, and get_the_title all with one DB call

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

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 badges
Add a comment  | 

1 Answer 1

Reset to default 3

These 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信