Contents
How to get the current page id in WordPress?
get_the_ID(); or $post->ID; returns the current page or post id in WordPress. But you need to ensure that your post is saved in wordpress post table. Other wise you can’t get the id , simply because of it is not an entry in wordpress database.
How to get the current page id in PHP?
You can get ID of the post in current page outside the loop using the technique below: Chosen answer is working only if you put it in the WordPress loop. Outside it will render useless. In your case you need to get ‘_GET’ and inside ‘post’… The code should look like this: Thanks for contributing an answer to Stack Overflow!
How to get post ID from WordPress plugin?
If you need to get post id from wordpress plugin, you can run your plugin in wp action hook, to get access to global $wp_query object. Here is simple test solution. Hope this will be of help for someone. Thanks for contributing an answer to Stack Overflow!
How to find the ID of a post?
You should see a list of all the posts on your website, and finding their IDs is as easy as mousing over each title: Mousing over a post’s title to see its ID. In the above example, the post ID is 1, and that number comes right after the posts= parameter.
Why do I need to enter my post ID in WordPress?
If you’re using a shortcode that requires you to specify a post, it will ask you to enter that post’s ID as a part of its parameters. Another, more advanced example occurs if you’re adding custom code to your website, but you only want to target specific pages.
How to contribute to WordPress development Stack Exchange?
Thanks for contributing an answer to WordPress Development Stack Exchange! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience.