There are a lot of situations when you might need to know what a specific page or post’s ID is in WordPress. A plugin might need it to exclude that page from a feature, for example. Alternatively, if you’re a developer, you could have to query that ID.
Page and post ID numbers are how WordPress identifies each piece of content on your website. Traditionally, the platform doesn’t display that information openly, but it’s easy enough to find if you know where to look for it. In fact, there are a lot of ways that you can get post IDs in WordPress.
In this article, we’ll show you five different ways to get post IDs in WordPress, ranging from the traditional to the unorthodox.
Let’s get to it!
Why It’s Useful to Know How to Identify WordPress Post and Page IDs
Internally, WordPress recognizes specific pages and posts by their ID numbers. That information is sometimes necessary if you’re using a plugin that asks you which posts you want to include or exclude from its effects.
WordPress post IDs are also necessary in some cases for building custom shortcodes. 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. In that scenario, you can tell WordPress that if a post or page matches the ID(s) you set, it should run the code that you want:
Regardless of which scenario you’re facing, there are a lot of ways you can find out what any post or page’s ID is in WordPress.
Let’s talk about what they are.
How to Get Post IDs in WordPress (5 Methods)
Finding post IDs in WordPress is remarkably simple if you know where to look. Let’s start with the most straightforward approach, and then work our way down the list.
1. Find The ID Within Each Post’s URL
The easiest way to find a post ID in WordPress is to go to your dashboard and click on the Posts menu option. 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.
If for some reason you can’t spot the ID clearly, you can open the post using the WordPress editor. That way, its URL will show up in your navigation bar, which should make the ID easier to spot:
Finding a WordPress post’s ID by checking out its URL.
Keep in mind that the post URLs you see in your dashboard might be different from the ones your visitors encounter. That’s because a lot of WordPress websites use custom permalink structures that don’t show post IDs at all.
The only two permalink structures that do include WordPress post IDs are the Plain and Numeric options.
Here are two quick examples of what those URL structures look like:
In both cases, the post ID is 1. Although both URL structures aren’t necessarily bad, in most cases, you’ll want to use permalinks that give visitors an idea of what content they can expect from each page.
2. Use Custom Code to Display Post IDs in The Posts Tab
If you take a look at your Posts tab, you’ll notice that it includes a lot of information about each piece of content, including its author, tags, categories, and more:
The WordPress Posts tab.
It’s possible to edit your theme’s functions.php file to add a new column to that table. This column will display each post’s ID, so you don’t have to dig into its URL to find that information.
That code includes an extra column in your Posts table. Keep in mind that if you’re using a plugin that adds extra data to that same table, you might need to modify the position indicated in the above snippet. Our example adds the new column in the fifth position (hence the “5” you see above), but you can adjust the code accordingly if needed.
Once the snippet is in place, save your changes to functions.php,and your Posts tab should look like this now:
A column that displays post IDs.
From this point on, you’ll be able to view post IDs right from this table.
3. Use a Plugin to Display Post IDs in WordPress
If you don’t want to modify your theme’s functions.phpfile, you can use a plugin that does the dirty work for you. Our recommendation is Show IDs by 99 Robots:
The Show IDs by 99 Robots plugin.
This particular plugin does exactly what we did during the last section, and it goes a bit further. On top of displaying IDs for your posts, it also includes that information for pages, categories, tags, media files, and more.
Once you activate the plugin, you’ll see a new ID column appear when you check out the full list of any of the elements we mentioned above. For example, here’s what our Pages tab looks like with the plugin set up:
The Pages tab with the Show IDs by 99 Robots plugin activated.
Any time you need a post ID, all you need to do is go to the Posts page and copy it.
4. Find Post IDs Within the WordPress Database
As you may know, the WordPress database stores all of the information on your website, including the IDs for each individual post, page, and piece of content. Some web hosts, including us, enable you to access your site’s database using a custom interface.
Tired of experiencing issues with your WordPress site? Get the best and fastest hosting support with Kinsta! Check out our plans
If you’re a Kinsta user, you can access your database through MyKinsta, our custom dashboard:
Accessing phpMyAdmin via the Kinsta Dashboard.
We enable you to access your database using phpMyAdmin. Once inside, open your site’s database and move over to the wp_posts table. You should see each post’s ID inside under the ID column to the left of post_author:
Finding post IDs within your WordPress database.
As usual, all you have to do now is copy and paste the post or page ID you need, and you’re off to the races.
5. Use Functions to Fetch WordPress Post IDs
If you’re a developer, you might not need to look up WordPress post IDs at all. With your superpowers, you can use functions to fetch the IDs you need using the right parameters.
Using functions to fetch WordPress post IDs can come in handy if you’re adding custom functionality or building your own plugins. However, if you only need to find the IDs for a few specific posts, then you’re better off using one of the other approaches we discussed above.
Although WordPress doesn’t clerly display post or page IDs, there are so many ways to find them. Knowing what each post’s ID is can come in handy for enabling features within plugins, using shortcodes, and even your own development projects.
If you’re looking for a specific WordPress post ID, there are five ways that you can locate it:
Find the ID within each post’s URL.
Use custom code to display post IDs in the Posts tab.
Use a plugin to display post IDs in WordPress.
Find post IDs within the WordPress database.
Use functions to fetch WordPress post IDs.
If you enjoyed this article, then you’ll love Kinsta’s WordPress hosting platform. Turbocharge your website and get 24/7 support from our veteran WordPress team. Our Google Cloud powered infrastructure focuses on auto-scaling, performance, and security. Let us show you the Kinsta difference! Check out our plans