Skip to content

How to Find WordPress Post ID (no code!)

It’s not uncommon for a WordPress plugin (especially one developed for a small team of users) to rely on WordPress post IDs. If you’ve been around WordPress a lot, finding these numeric identifiers for the piece of content you’re wanting to control via WordPress post ID is easy. If not, this Quick Guide is for you. We’ll cover two different ways that when given a page on a WordPress site you control. First I’ll cover how to find the WordPress post ID with the web page’s HTML, then we’ll locate the numeric ID of the post by editing that post.

Video How to: Finding Post ID in WordPress

In this video I walk through two different ways I’ll find the WordPress page’s numeric post ID. Both are a bit complex, but I’m guessing that one of them will feel comfortable to you. First is looking at the HTML (with “View Page Source”) and the other is “editing” the post and then looking at the resultant URL. Both methods should work even if you’re using Pretty Permalinks in WordPress. (Which all sites should today 🤓)

How to Find a WordPress Post ID in the Page HTML

Here’s how to find the WordPress post ID of a WordPress site when you’re not even logged in.

  1. Navigate to the page of your WordPress site you’d like to determine the numeric page ID for.
  2. In your web browser, view the source of the webpage. The way I most-often do this is with a right-click on a empty part of the web page, and a click on “View Page Source” (or similar) in the contextual menu.
  3. When you’ve got a mish-mash of HTML from the page (most often opened in a new browser tab) before you, you’ll want to search that (most easily invoked with a CMD or CTRL+F keyboard shortcut) for the string “postid-“. Usually you’ll find attached to a body tag in a WordPress site that HTML/CSS class, and the numeric post ID. So it’ll look like postid-1234. That’s precisely your numeric post ID.

How to Find the WordPress Page ID by Editing the Post

This is probably the easiest way for most people. The only downside: you must be logged into the WordPress site. That’s kind of step-zero of this method of find the page ID. After that it’s pretty simple:

  1. Navigate to the page of your WordPress site you’d like to determine the numeric post ID for. (You should be logged in to WordPress in the browser window you’re doing this in.)
  2. Because you’re logged in, the “admin bar” should be showing across the top of your WordPress site. If it is, click “Edit Post.”
  3. On the resulting page, look at your web browsers URL bar (you may need to click into that bar to see the important part). In the URL, you’ll see a segment that looks something like ?post=1234.  That 1234 (yours probably won’t be 1234 😛) is the numeric ID or post_id of this specific WordPress post.

Developer? Here’s the answer you might have been seeking

If you’re happy with the above, the below is superfluous.

But I can imagine a developer or two finding this page, wanting the WordPress PHP function to find the post ID. If that’s you, the most-often-right answer is get_the_ID(). That relies on you being within the WordPress loop, but for most of the time I’m looking to do this as a WordPress developer I am within the loop, or close enough for get_the_ID() to work. Hope that’s helpful 🙂

Yay! 🎉 You made it to the end of the article!
David Hayes

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
November 22, 2019 4:46 am

If anyone looking to get WordPress post ID outside of the loop, you can use the following code.

global $post;
echo $post->ID;

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!

Would love your thoughts, please comment.x

Most Searched Articles

Best JavaScript Libraries and Frameworks: Try These 14 in 2024

In this post, we look at the best JavaScript libraries and frameworks to try out this year. Why? Well, with JavaScript being available in every web browser, this makes it the most accessible programming language of ...

20 Best Free WordPress Themes for 2024 (Responsive, Mobile-Ready, Beautiful)

If you're looking for only the best free WordPress themes in the market for this year, then you're in the right place. We have more than enough such themes for you right ...

12 Best WordPress Hosting Providers of 2024 Compared and Tested

Looking for the best WordPress hosting that you can actually afford? We did the testing for you. Here are 10+ best hosts on the market ...

Handpicked Articles

How to Make a WordPress Website: Ultimate Guide for All Users – Beginners, Intermediate, Advanced

Many people wonder how to make a WordPress website. They’ve heard about WordPress, its incredible popularity, excellent features and designs, and now they want to join the pack and build a WordPress website of their own. So, where does one get ...

How to Start an Ecommerce Business: Ultimate Guide for 2024

Is this going to be the year you learn how to start an eCommerce business from scratch? You’re certainly in the right place! This guide will give you a roadmap to getting from 0 to a fully functional eCommerce business. ...