In WordPress, every item that you create or upload, or is created and uploaded by users has a unique ID assigned to it. It is basically a unique number used to query, identify and read the item for display from the database. This ID is present for almost everything—posts, pages, categories, tags, users, media uploads, comments, and menus. Sometimes, there is a need to identify the ID of such items.
The ID number is used by themes or plugins for special purposes. For example: Featured posts or post sliders require you to input IDs of posts or pages to be featured. Similarly, menu IDs is required by themes to use as the default menu at a certain location. Another real example is Google XML Sitemap Plugin requires the IDs of posts and categories that you want to exclude from the automatically generated sitemap.
In this post, we are going to learn how to get such unique IDs of posts, pages, categories, tags, users, menus, comments and media uploads in WordPress. The basic idea is to edit a content and look at the URL in the address bar for a number. That will give us the unique ID.
Finding ID of Posts
- In WordPress Administration go to Posts > All Posts.
- Edit the post for which you want to find the ID.
- Check the address bar for the current URL.
- There will be a post=<number>. That number is the post ID that you are looking for.
The basic idea of finding the ID number is the same for the rest of the content. Here are some examples and steps for them:
Finding ID of Pages
- Go to Pages > All Pages in WordPress Admin.
- Click on the edit option of a page.
- In the address bar the post= section of the URL will hold the page ID.
Finding ID of Categories
- Go to Posts > Categories.
- Edit a category.
- You’ll find the category ID number represented by tag_ID.
Finding ID of Tags
- Open Posts > Tags.
- To find the exact tag, browse the list or hit the search button.
- Once you’ve found it, click on edit.
- In the address bar, get the number from the value of tag_ID.
Finding User ID
- In admin dashboard, go to Users > All Users.
- Find a particular user and click on edit.
- The URL in the address bar will display something like: http://yoursite.com/wp-admin/user-edit.php?user_id=13&wp_http_referer=%2Fwp-admin%2Fusers.php
- The user_id=9 tells us what the user ID is.
Please note that while editing the first user or the admin user that was used while setting up WordPress, the URL will not show the user ID. It is always 1 for the first user. For the usernames created after that, the address bar will give the unique ID number.
Finding ID of Media
- Open Media > Library section and search to find the exact media file.
- Click on the thumbnail of the media and it will open the attachment details.
- In the address bar, from an URL like http://yoursite.com/wp-admin/upload.php?item=197 get the value of item.
Finding ID of Comments
- Click on the Comments link in the admin menu.
- Find the exact comment by browsing or searching.
- Click on edit.
- In the address bar you will get an URL that looks like: http://yoursite.com/wp-admin/comment.php?action=editcomment&c=128
- The value of c is the comment id.
Finding ID of WordPress Menu
In WordPress more than one menu can be created and placed in various sections of the theme. There is a primary menu and more than one secondary menus. To find their ID:
- Go to Appearance > Menus.
- From the select a menu to edit drop-down, choose a menu and click on select; even though it is presently selected as it is the primary menu.
- The URL in address bar will change to something like: http://yoursite.com/wp-admin/nav-menus.php?action=edit&menu=5.
- The menu=6 tells us the menu id.