After recently writing my post “Include a Post within a Page or Post“, I was in the process of writing a tutorial to give you an easier way to find the Post ID, by adding a column in the post editor screen.
Well, it seems that WP Snipp pipped me to the post as they just published a post doing exactly that. So rather than go through the rigmarole of writing the snippet myself, I’m going to give you his snippet. Drop it into your functionality plugin to use it:
// ADD COLUMN IN EDITOR FOR POST ID //
function posts_columns_id($defaults){
$defaults['wps_post_id'] = __('ID');
return $defaults;
}
function posts_custom_id_columns($column_name, $id){
if($column_name === 'wps_post_id'){
echo $id;
}
}
add_filter('manage_posts_columns', 'posts_columns_id', 5);
add_action('manage_posts_custom_column', 'posts_custom_id_columns', 5, 2);
add_filter('manage_pages_columns', 'posts_columns_id', 5);
add_action('manage_pages_custom_column', 'posts_custom_id_columns', 5, 2);
Now when you go to your posts (or pages) screen, you’ll see that there’s an additional column that shows your post ID for easy reference. Pretty handy huh? Thanks for the snippet Kevin.
Dave Clements has been building websites for close to a decade and in 2010, he formalised that by starting his own company, The UK Edge. He now works on a variety of web projects, from simple tasks like installing a new WordPress site, to consulting on problems, or redesigning his clients' sites. He also runs Do It With WordPress, a site dedicated to providing free tutorials on WordPress.
When he's not building your new website, you can find Dave eating Wheat Thins, spending time with friends and family, watching Indie films, fostering kittens from the local Humane Society, listening to some dubstep, dance and electronic rock, and exploring the world.
I don’t think it matters about the size of the blog… whether you have 10 posts or 10,000, it’s a case of whether you need to know the post ID (for applications such as using a shortcode to display a post within a post).
Yeah, I was thinking of writing a quick tutorial that shows information about the post to just the admin on the post itself, including the Post ID for instance. Much simpler than hunting for it in a URL.
January 4, 2012 at 10:03 am
This is very useful. Considering blogs that have thousands of articles, knowing the post id can help a lot.
But small blogs don’t need it, I think… or not? anyway, great post
January 4, 2012 at 10:05 am
I don’t think it matters about the size of the blog… whether you have 10 posts or 10,000, it’s a case of whether you need to know the post ID (for applications such as using a shortcode to display a post within a post).
January 8, 2012 at 2:24 pm
Hey glad to see that you like the snippet and yes this was something that I have found immensely useful.
January 19, 2012 at 2:41 am
This is pretty cool, Dave. I just go to the permalink at the top of a post a click edit. The serial number shows up. I don’t really edit it!
January 19, 2012 at 11:45 am
Yeah, I was thinking of writing a quick tutorial that shows information about the post to just the admin on the post itself, including the Post ID for instance. Much simpler than hunting for it in a URL.