Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom Post Types and Category Archives
Tagged: category archives, CPT, genesis.2.1.2
- This topic has 7 replies, 4 voices, and was last updated 9 years, 7 months ago by cbryant.
-
AuthorPosts
-
May 13, 2013 at 1:33 pm #40708SaraGraybillMember
I have created a custom post type for my website listing the services available. I am using categories for the custom post type and I can't seem to figure out how to show the service cpt in the category archive. It just says no posts match your criteria. Any ideas?
http://www.cobbengr.com/civilservants/May 13, 2013 at 7:50 pm #40797Brad DaltonParticipantJust noticed your footer links not working.
I think you may have setup your custom post types incorrectly but hard to say from here. I may be wrong.
June 19, 2013 at 9:37 pm #4684301themasMemberTry something like this to be able to have categories displayed across all CPTs:
//enables categories to be used across different post types
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag() || is_home() && empty( $query->query_vars['suppress_filters'] ) ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','business', 'academic', 'partners', 'people', 'facilities','programs' ,'nav_menu_item');
$query->set('post_type',$post_type);
return $query;
}
}September 23, 2014 at 1:04 pm #125458cbryantMemberI'm running into the same problem described by SaraGraybill.
I've set up a CPT called "sermon".
Set it up manually in my functions.php. (code at bottom).
The CPT itself correctly uses the Genesis 2.0 Archive template support for CPTs.
That is: I can view a complete list of all CPTs on an Archive page, and add info to it using Genesis Archive settings. All good.However, this CPT has "categories" enabled.
Yet, when I click on the "Filed under 'Category Name' on a single CPT it brings me to the standard Genesis Category Page (good) but gives me the error "Sorry, no content matched your criteria."The category heading and title which I added in the backend do appear correctly on the category page.
So... it's as if it's seeing the Category correctly - but not seeing the CPTs within the category .@ 01themas idea seemed to make sense. But I had no success with it.
Is there a simple Genesis function for adding Genesis Category Archive Support to CPT Categories (and not just to the Post Type)?
Any suggestions are welcomed.
I'm working locally so have no link to provide.
Here is my CPT registration code... in case maybe anyone spots a glaring omission on my part....
Thanks in advance for any thoughts or comments.
Chris
add_action('init', 'register_cpt_sermon'); function register_cpt_sermon() { register_post_type('sermon', array( 'label' => 'Sermons', 'description' => 'Audio Recordings of Sermons', 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'capability_type' => 'post', 'map_meta_cap' => true, 'hierarchical' => true, 'rewrite' => array('slug' => 'sermon', 'with_front' => 1), 'query_var' => true, 'has_archive' => true, 'menu_position' => '5', 'supports' => array('title','editor','excerpt','custom-fields','revisions','thumbnail','author','page-attributes','genesis-cpt-archives-settings'), 'taxonomies' => array('category'), 'labels' => array ( 'name' => 'Sermons', 'singular_name' => 'Sermon', 'menu_name' => 'Sermons', 'add_new' => 'Add Sermon', /*I've included a full series of labels - but left them out for readability here*/ ) ) ); }
September 23, 2014 at 1:16 pm #125460Brad DaltonParticipantSeptember 23, 2014 at 1:21 pm #125461Brad DaltonParticipantThis is what i use http://wpsites.net/web-design/add-support-for-creating-custom-taxonomies-to-existing-portfolio-custom-post-type/
However, i also use this for the CPT http://wpsites.net/web-design/add-custom-post-type/
September 23, 2014 at 3:05 pm #125478cbryantMemberHi Brad,
Thank you for responding.
The code was generated by Custom Post Types UI plugin.
I'm going to take a look at your recommendations and links and will post the results.
Thanks again - Chris
September 23, 2014 at 3:45 pm #125481cbryantMemberThis code snippet did the trick:
//* Show Sermon CPT entries in addition to Posts in Category Archive Pages add_action( 'pre_get_posts', 'cpt_entries_and_posts_in_archives' ); function cpt_entries_and_posts_in_archives( $query ) { if ( $query->is_main_query() && !is_admin() && is_category() ) { $query->set( 'post_type', array( 'post', 'sermon' ) ); } }
(props Bill Erickson)
@Brad - thanks for your input. Your wpsites is a valuable resource! -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.