I have a page in WordPress that loops posts in a specific category. In sidebar.php, I want to get a list of sub pages and display them as a menu. However, when using get_the_ID() or $post->ID, it returns the ID of the last post that was looped, not the page.
How do I get the ID of the page in the side bar after I have looped posts in the page?
If you’re using a page template, you should do the following things:
post_parent)So, put this at the top of your page template:
And then put this in your sidebar:
That should get you what you want.