So it’s friday, I’ve been coding all day and I thought I’d share some of the cool snippets I’ve come across and/or developed today. I’ve mostly been working with Custom Post Types and Taxonomies, so let me share some of that goodness. Let’s geek out in a bit, but first let me show you why this is cool, be sure to click the image, so you can see which functionality I’ve added to the otherwise boring custom posts overview screen:
Click for large version
Add columns to the overview page for a Custom Post Type
So you’ll want to add some columns to your post type’s overview page, or remove some. Don’t forget to replace <CPT> with your own custom post type in all these examples:
Ok so far this is all fairly simple. Now let’s go a bit more advanced. Let’s say you have a custom taxonomy attached to that custom post type and you want to show a filter for that custom taxonomy on the custom post types overview page, just like you have a categories drop down on the posts overview page. This code was taken (though slightly modified) from this thread.
Let’s first add that dropdown / select box to the interface:
[code lang=”php”]// Filter the request to just give posts for the given taxonomy, if applicable.
function taxonomy_filter_restrict_manage_posts() {
global $typenow;
// If you only want this to work for your specific post type,
// check for that $type here and then return.
// This function, if unmodified, will add the dropdown for each
// post type / taxonomy combination.
Note that for these last two snippets to work, query_var must have been set to true when registering the custom taxonomy, otherwise this’ll never work.
Bonus: Add Custom Post Type to feed
This one came courtesy of Remkus de Vries a while back and was helpful today, adding a custom post type to your site’s main feed, don’t forget to replace <CPT> with your own custom post type:
[code lang=”php”]// Add a Custom Post Type to a feed
function add_cpt_to_feed( $qv ) {
if ( isset($qv[‘feed’]) && !isset($qv[‘post_type’]) )
$qv[‘post_type’] = array(‘post’, ‘<CPT>’);
return $qv;
}
Joost is an internet entrepreneur and the founder of Yoast. He has a long history in WordPress and digital marketing. On our blog, he has written a lot about SEO in general, technical SEO and important topics related to SEO.
November 21 - 22, 2025
Team Yoast is Attending, Organizing, Sponsoring at WordCamp Pisa 2025! Click through to see who will be there, what we will do, and more!
See where you can find us next »
20 November 2025
Learn how to start your SEO journey the right way with our free webinar. Perfect for beginners seeking to improve website performance 🚀 .
All Yoast SEO Webinars
Discussion (20)
teebeeJul. 15, 2011
One thing that is confusing me is where these snippets go. Are they all in the functions.php file or in multiple files? If in multiple files maybe you can update your post to tell which file each snippet goes into. Thanks!
Danny G SmithJul. 02, 2011
This is a wonderful tutorial, I am using it on a site that I am working on now. One thing that is not intuitive to me is why you can only fire the functions to “Filter Custom Posts by Custom Taxonomy” once, even if you create more than one custom post type. If they run more than once, none of them work. Oh, well, great stuff.
DanJun. 24, 2011
Where is the Order field in Custom Post Types? Is this something that has to be added when registering the CPT?
DanJun. 24, 2011
Just answered my own question. Added the Page Attributes to the Supports argument when I Register Post Types.
MarcusJun. 23, 2011
nice find, great snippets, bookmarked for future reference :)
Bryan CarterJun. 23, 2011
Excellent information, thanks for the snippet/tutorial!
SanderJun. 23, 2011
Thanks Joost, this is stuff I can actually use on some projects I’m working on right now.. Thanks for sharing!
Sander
sergeJun. 21, 2011
Another tip to add our CPT in the right now widget on the dashboard
function cpt_in_right_now() {
$num_cpt = wp_count_posts( 'CPT' );
echo '';
$num = number_format_i18n( $num_cpt->publish );
$text = _n( 'CPT-NAME-SINGULAR', 'CPT-NAME-PLURAL', $num_cpt->publish );
if ( current_user_can( 'edit_post' ) ) { // or edit_CPT if defined
$num = "$num";
$text = "$text";
};
echo '' . $num . '';
echo '' . $text . '';
echo '';
}
add_action('right_now_content_table_end','cpt_in_right_now');
enjoy
SergeJun. 21, 2011
Really helpfull, but some remarks :
first snippet : use manage_edit-CPT_columns
second snippet : use manage_CPT_posts_custom_column
or global $post;
if ($post->post_type == "CPT") :
switch ( etc..
Rev. VoodooJun. 20, 2011
Good stuff here, I’d done some custom column stuff for my CPTs before, but this is icing on the cake so to speak!
Lars KoudalJun. 20, 2011
I agree with the others, great work as always.
You actually just given me a great idea, thanks :-)
Nicusor DumbravaJun. 24, 2011
If you intend to build a plugin …. let us know :)
CraigJun. 19, 2011
Man, awesome info you put out on your site, I put “Quix” in my tool bar two days ago, mind boggling what you can do with that tool. Installed Robots Meta on 3 sites we run, 1st site saw a 1000% increase in long tail keywords in the first month, second site saw a 200% increase, 3rd site 100% increase. Consider me a huge fan of your work :) Commenting so I can subscribe to your newsletter.
JoshJun. 17, 2011
Great article! I’ve been toying around with custom post types a lot lately, adding / sorting columns isn’t something I’ve considered before – thanks!
JµJun. 17, 2011
That’s not a snippet… It’s a tutorial ! Thanks for sharing !
DanJun. 17, 2011
This is a tutorial with great snippets. Joost just knows that most of us just end up copy and pasting anyway.
MicahJun. 17, 2011
This is essential for plugin developers to learn. I have implemented columns and filters on my Promotion Slider plugin, but never really got around to making the columns sortable. Thanks again for a great post!
Nicusor DumbravaJun. 23, 2011
If you use any Joost’s code do not forget to give him some credits :)
Micah Wood, just kidding :)
MicahJun. 24, 2011
Ha ha :) You do have to be careful though, Joost’s code is so well written, that if you look to see how he did something, you can’t help but be tempted just to copy it! But hey, I have no problem giving credit where credit is due…
Nicusor DumbravaJun. 24, 2011
Yes Micah, especially since these credits add value to your plugin. I am not a programmer, but I peek the code of plugins that I use and I like it when I see mentions with credits given to reputable developers … gives me confidence in the product overall ;)
One thing that is confusing me is where these snippets go. Are they all in the functions.php file or in multiple files? If in multiple files maybe you can update your post to tell which file each snippet goes into. Thanks!
This is a wonderful tutorial, I am using it on a site that I am working on now. One thing that is not intuitive to me is why you can only fire the functions to “Filter Custom Posts by Custom Taxonomy” once, even if you create more than one custom post type. If they run more than once, none of them work. Oh, well, great stuff.
Where is the Order field in Custom Post Types? Is this something that has to be added when registering the CPT?
Just answered my own question. Added the Page Attributes to the Supports argument when I Register Post Types.
nice find, great snippets, bookmarked for future reference :)
Excellent information, thanks for the snippet/tutorial!
Thanks Joost, this is stuff I can actually use on some projects I’m working on right now.. Thanks for sharing!
Sander
Another tip to add our CPT in the right now widget on the dashboard
function cpt_in_right_now() {
$num_cpt = wp_count_posts( 'CPT' );
echo '';
$num = number_format_i18n( $num_cpt->publish );
$text = _n( 'CPT-NAME-SINGULAR', 'CPT-NAME-PLURAL', $num_cpt->publish );
if ( current_user_can( 'edit_post' ) ) { // or edit_CPT if defined
$num = "$num";
$text = "$text";
};
echo '' . $num . '';
echo '' . $text . '';
echo '';
}
add_action('right_now_content_table_end','cpt_in_right_now');
enjoy
Really helpfull, but some remarks :
first snippet : use
manage_edit-CPT_columnssecond snippet : use
manage_CPT_posts_custom_columnor
global $post;etc..if ($post->post_type == "CPT") :
switch (
Good stuff here, I’d done some custom column stuff for my CPTs before, but this is icing on the cake so to speak!
I agree with the others, great work as always.
You actually just given me a great idea, thanks :-)
If you intend to build a plugin …. let us know :)
Man, awesome info you put out on your site, I put “Quix” in my tool bar two days ago, mind boggling what you can do with that tool. Installed Robots Meta on 3 sites we run, 1st site saw a 1000% increase in long tail keywords in the first month, second site saw a 200% increase, 3rd site 100% increase. Consider me a huge fan of your work :) Commenting so I can subscribe to your newsletter.
Great article! I’ve been toying around with custom post types a lot lately, adding / sorting columns isn’t something I’ve considered before – thanks!
That’s not a snippet… It’s a tutorial ! Thanks for sharing !
This is a tutorial with great snippets. Joost just knows that most of us just end up copy and pasting anyway.
This is essential for plugin developers to learn. I have implemented columns and filters on my Promotion Slider plugin, but never really got around to making the columns sortable. Thanks again for a great post!
If you use any Joost’s code do not forget to give him some credits :)
Micah Wood, just kidding :)
Ha ha :) You do have to be careful though, Joost’s code is so well written, that if you look to see how he did something, you can’t help but be tempted just to copy it! But hey, I have no problem giving credit where credit is due…
Yes Micah, especially since these credits add value to your plugin. I am not a programmer, but I peek the code of plugins that I use and I like it when I see mentions with credits given to reputable developers … gives me confidence in the product overall ;)