It is a good idea to store values from the global $post if they are used multiple times?
Question
I am wandering if it is a good idea to store values from the global $post
if they are used multiple times like in the example below, or is having no effect on performance?
$post_id = $post->ID;
echo get_the_title($post_id);
echo get_the_post_thumbnail_url($post_id);
// or
echo get_the_title($post->ID);
echo get_the_post_thumbnail_url($post->ID);
My thought is that in the second example, it must query the global $post
every time, while in the first just once, and this may affect the performance.
Thank you
0
3 months
0 Answers
9 views
0
Leave an answer
You must login or register to add a new answer .