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 🙂


1 Response

Comments

Add a Comment

Your email address will not be published. Required fields are marked *