This function adds custom post types to the author’s posts on the author page of a WordPress blog. In line 3 below, my custom post type is ‘skaterstatus’. Replace that with your own custom post type. You can leave in ‘post’ or remove it, depending on your needs. You can add more custom post types into the array in the same format.
function custom_post_author_archive($query) { if ($query->is_author) $query->set( 'post_type', array('skaterstatus', 'post') ); remove_action( 'pre_get_posts', 'custom_post_author_archive' ); } add_action('pre_get_posts', 'custom_post_author_archive');
Andy
May 13th, 2012 at 12:05 pm
This works great on the archives page, but unfortunately it also lists all CPT posts in the admin post edit list. Is there a way to avoid this?
Isabel
May 16th, 2012 at 11:55 pm
What is it you’re trying to avoid? The CPT menu item on the dashboard (admin)? To hide the CPT menu item from admin, see
Remove Menu Items From WordPress Dashboard. Not sure if that’s what you mean. Hope it helps. Thanks for stopping by.
Andy
May 17th, 2012 at 7:04 am
Sorry, I wasn’t very clear in my comment. I have 2 custom post types, Recipes and Photos. My goal is to have these posts types appear in my author.php page along with the standard WP posts. Adding the code snippet to my functions.php file accomplished this. But, in the WP admin, when I click Recipes from the menu instead of seeing a list of all the recipe posts, I now see a list of all Recipe and Photo posts. So the snippet must be adding the custom posts not only to the front end author page, but also to the admin backend.
To solve this I removed the code from functions.php and added this to my author.php file:
Right before my loop starts:
Andy
May 17th, 2012 at 7:06 am
My code didn’t post. I’ll try a link from pastebin.com: http://pastebin.com/iiKAP4kF
Nojan
May 12th, 2013 at 8:43 am
Very useful. thanks.
Is there something like this to add custom post types to monthly archive pages?