Where To Find WordPress Page ID And Post ID – 4 Methods

Where To Find WordPress Page ID And Post ID – 4 Methods

The page and post id is not something WordPress is displaying openly, but you can easily find it, and I have 4 different methods, where some are with submethods to find it. I use method 1 mainly when I need to find the page and post id.

The easiest way to find the page and post ID is to go to your WordPress admin area and go to posts or pages, depending on what you need the id for. Next, click on the page or post you wish the id for. Now in the URL, you will see something like post=1502. In this case, 1502 is my post id.

Now you might want to use the page or post id in a different situation than just needing to see it for yourself, so I have 4 methods, where the method I just described can be done in 3 different ways.

What Is A WordPress Page And Post ID?

An ID, whether for a WordPress post or WordPress page, is a unique identifier for that specific page. It’s used for identification and relations in your database.

For example, when you add a tag or a category to your post or page, a relation is made between your post/page ID and the tag or category’s id. This tells your WordPress system that your page/post is related to a tag or a category.

You can use your id yourself if you’re handy with PHP to do a lot of different things, such as fetching the featured image of a post. You can fetch the content of a post based on the ID and much more.

What it’s most commonly used is excluding and including it in specific plugins. You might want to exclude it from being lazy-loaded in a plugin. Or you want to include it in a post filter based on ID.

As you can see, there are many use cases for it, so let me elaborate on the first solution, which based on my own experience, is the easiest and most straightforward way of finding the page/post id.

[cboxarea id=”cbox-DZ7YzH84qT48YAf1″]

1. Find the Page And Post ID In The URL

There are 3 ways you can find the page and post ID in the URL. And the first way is super simple, but it doesn’t work if you’re using Safari. But if you’re in Chrome or similar browsers, you can simply hover on the edit link for the post you wish the ID for, and then in the bottom left corner of your browser, you can see the number right after “post=”.

get page and post id by hovering

The following solution is to click on the edit link. It will now redirect you to the page where you can edit the post or page, and here, if you look in the URL, you will also see the ID right after “post=”.

get page and post id from URL

The last solution is to go to your permalink settings in the left menu in your settings menu point. Then change your permalink structure to plain as your ID would now be visible on the side that your visitors see, then simply visit the page or post wish you want to get the ID from, and then you’ll see it in the URL right after “p=”.

permalink to find page or post id

2. Use A WordPress Plugin To Find the Page And Post ID

If you want a more permanent solution where you can see the post or page id in your WordPress admin constantly as a column, then you need to install a plugin.

I recommend the plugin Reveal IDs, which is often updated and is used by more than 60.000 websites with excellent ratings.

Install and activate the plugin in your WordPress admin area. With the plugin installed, you can now go to either your posts or pages menu point and see a new column has appeared, and in this column, you’ll find your ID of the page or post. No setup is required to use this plugin.

reveal id wordpress plugin

3. Add Custom PHP Code To Display Page And Post ID

Now you might be in a situation where you want to use the page and post id in your PHP code in your theme or a specific plugin. There are multiple ways of getting the page depending on where you want the id.

If your context is on the page itself, this could be a file named single-post.php, then the most straightforward way is using the function:

echo get_the_id();

If you need the id of a page or post where you’re not on the specific page or post, then you can either fetch it by the URL slug, which is the part that defines your post or page in the URL after your domain. Or you can fetch the ID by title. The title is the most insecure way of doing it, as the title change more often than the slug.

$getPageID = get_page_by_title( 'Enter your page title', '', 'page' );
echo $getPageID->ID;

That’s how you do it with the title. If you wish to use the URL slug instead, it looks like this.

$getPostID = get_page_by_path('post-url-slug', '', 'post');
echo $getPostID->ID;

4. Find The Page And Post ID In PHPMyAdmin

The last solution is using PHPMyAdmin, and this solution is only for you if you know your database and PHPMyAdmin. Otherwise, I would recommend you go with 1 of the other 3 solutions.

Now sign in to your PHPMyAdmin. This can be done via your hosting provider. Once you’re into your PHPMyAdmin, choose your database, which is given to you by your hosting provider as well.

Being signed into PHPMyAdmin and on your database, you now need to choose the table named wp_posts, it might be named differently in your database as you might’ve chosen a different prefix, but it ends on _posts.

phpmyadmin wp posts

When you’ve clicked on the wp_posts table, you’re now in the table which contains all your posts and pages, and you’ll have a row named ID. So you’ll need to find the title of your post or page and then look at the ID next to the post or page. And then you have your ID.

wp posts id column

If you want to see how you can get the attachment URL by post id to further your development, then I’ve written an article elaborating on that in multiple ways.


How do I change my WordPress page ID?

You should never change your WordPress page ID or your WordPress post ID. Your ID has a ton of relations in the system to categories, tags, media and more. If you change the ID of your post or page, you will mess up a lot of relations, and your WordPress website might stop working.

If you still want to try it, you can sign in to your database via PHPMyAdmin, go to wp_posts, find your post and simply give it a new ID.

Similar Posts

Leave a Reply

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