Right now I am using:
$wp_query->post->ID;
I want to know if there is a better way for getting the post id that consumes less resources?
Right now I am using:
$wp_query->post->ID;
I want to know if there is a better way for getting the post id that consumes less resources?
Comments are closed.
An alternative to your way would be to access the
$post
global:But
EDIT, pertaining to comments:
–> Needs to be run inside the Loop.
If the latter is the case, you, or some plugin you are using, has not properly reset postdata.
I have no idea what it is you are writing. But if you experience resource bottlenecks or inefficiency, retrieval of the current post ID is likely not the cause.
You can also use
get_queried_object_id()
in conjunction withis_main_query()
outside the LoopNote that this function will return author id on a archive page, category id on a category archive, etc.