Need to get a WordPress post ID or page ID but not sure where to look? Then, you are in luck today.
IDs are unique numbers for posts or pages on a WordPress website.
Since titles and other data about content can change, WordPress uses IDs as unique identifiers to recognize individual content.
There are several use cases for WordPress post IDs. An instance is when building a custom shortcode that requires you to specify a post ID.
Also, some plugins will ask you for post IDs to include or exclude them from their functions.
Irrespective of your situation, getting WordPress post ID is easy if you know where to look.
This article will show 4 of the simplest ways to get post IDs in WordPress.
Frequently Asked Questions
What is the Post ID in WordPress?
A Post ID is a unique identifying number that WordPress automatically assigned for each post.
Pages on WordPress websites are also assigned these unique IDs.
Besides pages and posts, categories, tags, and media on WordPress also have distinct IDs.
Even when every other data about a post or page changes, the ID number remains unchanged.
What Should I Get a Post ID in WordPress?
There are several ways to get a post ID in WordPress.
The fastest of which is to go to the Post page from your admin dashboard and hover over the post.
This will reveal the post ID as part of a URL string and you can extract your ID from there.
We’ll show you how in the coming sections.
What You’ll Need to Get WordPress Post ID
- WordPress Admin Access: You need access to the admin dashboard of the WordPress site in question before you can get any of its post IDs. An admin level or super admin access is required.
- Hosting Account cPanel: Getting post IDs on a WordPress website may warrant adding a few code snippets to your theme PHP file. You can do this either from your hosting cPanel or via the Theme File Editor in your admin dashboard.
- WordPress Get Post ID Plugins: Some plugins allow you to get post ID easily without going through the manual process. By installing and activating a get post ID plugin, you’ll get WordPress Post ID with a few clicks.
How to get WordPress Post ID: 4 Simple Ways
- Get Post ID from WordPress URL
- Get Post ID from WordPress Database
- Using Worpdress Function to Get Post ID
- Using a Plugin to Get WordPress Post ID
Get Post ID from WordPress URL
The fastest way to get a post ID in WordPress is to extract it from the post URL.
You can get the URL from the All Posts page in your admin dashboard.
See the steps below.
Log in to your WordPress admin dashboard, Select Post on the left panel, and choose All Posts from the menu.
This will take you to all the posts on your website.
To find the ID of any post, just put your mouse over the post.
As you do so, you’ll see the URL of the post at the bottom left of your screen.
In that URL, the number after the “post=” and before the “&“ is the post ID.
In this example, our Post ID is 11260
Alternatively, you can proceed to open the post in the WordPress editor by clicking the Edit button under the post.
Once the editor opens, you will find the post ID in the address bar.
As above, the number after the “post=” and before the “&“ is the post ID.
Get Post ID from WordPress Database
Another way to get a WordPress post ID is via your website database.
The database has all the information about every content on your website, including post IDs.
To use databases to get post ID in WordPress, you’ll have to log in to your hosting account cPanel.
We use Hostinger web hosting account for this tutorial.
However, the steps are the same for other web hosting providers.
Here are the steps;
Log in to your hosting account dashboard and click on Databases.
Once the database page opens, select the database of the website you want to get post IDs from, then click on the Enter phpMyAdmin button next to it.
Inside phpMyAdmin, locate the wp_post and double-click to open it.
Next, go to the ID column on the table.
You’ll see the IDs of all posts in a column next to each post title.
Now you can copy the post IDs and paste them where you need them.
Using Worpdress Function to Get Post ID
One of the advanced ways to get post IDs is to use a WordPress function.
A WordPress function is a PHP command that your theme uses to display the content of a post within template files.
We’ll show you how to use WordPress global $post variable to get post IDs.
Log in to your WordPress admin dashboard, go to Appearance on the left panel and select Theme File Editor from the menu.
On the next screen, go to the right sidebar under Theme File.
Locate the Single post (single.php) from the list and click to open.
Once the single.php file opens, paste the following code snippets under get_template_part() function as in the screenshot below.
global $post;
echo $post->ID;
Next, click the Update File button to save the changes.
Now, to get Post ID, go to your all post page and click the view under any post.
Once the post loads, scroll down, and you’ll see the post ID at the bottom.
Using a Plugin to Get WordPress Post ID
If editing the theme file is too complex for your liking, or you want to get IDs of multiple posts, using a plugin is the easiest way.
We’ll show you 2 free plugins for this purpose and how to use them to get post ID step by step.
Using the Reveal IDs Plugin to Get WordPress Post ID Step by Step
The Reveal IDs plugin automates the process of getting IDs that we go through in the steps above.
This plugin runs the get post ID function to collect post IDs and display them in your WordPress dashboard.
Here’s how to get post IDs with this plugin.
After installing and activating the plugin, Reveal IDs don’t need any configuration.
Just go to the All Posts page within your admin dashboard.
You’ll see that an extra column titled ID has been added to your Post page table.
This column contains the ID of the posts in the corresponding rows.
Using the Show IDs Plugin to Get WordPress Post ID Step by Step
Another get post ID plugin that will save you the stress of switching in and out of editors is the Show IDs plugin by DraftPress.
Trusted by over 20,000 websites, it does beyond getting post ID, it also displays IDs for pages, media, tags, files, categories, etc.
This plugin works the same way as the Reveal IDs plugin.
Once you install and activate it, it adds a new ID column to your Posts page.
So whenever you need a Post ID, all you need to do is go to the Posts page and copy it.
More Helpful WordPress Tutorials:
- How to Build a Website With WordPress: With WordPress, becoming a website owner is easy. Learn how to build a website using the world’s most famous CMS step by step.
- How to Add a New Post in WordPress: Wondering how to create your first WordPress post? This detailed guide will walk through the A–Z of adding a new post in WordPress.
- How to Use a WordPress Robots.txt File: You can dictate which part of your website you want search engines to crawl with the help Robot.txt file. Use this guide to do it.
Wrapping up
There are many more ways to get a post ID in WordPress, but as we’ve promised at the beginning of this post, these are the simplest.
And of course, you can use the methods above to get the ID for other content types in WordPress, media, files, tags, and categories.
We hope you find this guide useful.
If you have any questions about WordPress development, feel free to drop a line in the comments below.