I have a blog index page which only lists 1 custom post at a time on the index page (it is paginated). I am trying to get the ID of that post from outside the loop (in the footer, after the loop) but am unable to do so. When I call it, i get the ID of the next post not the current one.
global $post;
echo $post->ID; // return ID of the next post, not the current one. not sure why.
I know that this is an unusual setup (my index page is basically a single post page). Should I change my index page design, or is there a simple way for me to just get the current post ID without throwing away all my current work?
the_post()
iterates the index in the array of posts being looped. developer.wordpress.org/reference/functions/the_post – jdm2112 Jun 29 '20 at 15:09get_previous_post()
developer.wordpress.org/reference/functions/get_previous_post. That will return the whole post object though so $var->ID to get the ID. – jdm2112 Jun 29 '20 at 15:10