• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Different content types on shared category archive page

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Different content types on shared category archive page

This topic is: resolved

Tagged: archive page, custom content type, executive pro, shared taxonomy, taxonomy

  • This topic has 1 reply, 1 voice, and was last updated 10 years, 5 months ago by nkleekamp.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • January 20, 2015 at 4:03 pm #138133
    nkleekamp
    Member

    Hello! I created a custom content type called "Publication" based on the portfolio content type code in the Executive Pro child theme, with some additions.

    //* Create Publication custom post type
    add_action( 'init', 'executive_publication_post_type' );
    function executive_publication_post_type() {
    
    	register_post_type( 'publication',
    	array(
    		'labels' => array(
    			'name'          				=> __( 'Publications', 'executive' ),
    			'singular_name' 				=> __( 'Publication', 'executive' ),
    			'add_new'								=> __( 'Add New', 'publication'),
    			'add_new_item'  				=> __( 'Add New Publication' ),
    			'edit_item'							=> __( 'Edit Publication' ),
    			'new_item'							=> __( 'New Publication' ),
    			'all_items'							=> __( 'All Publications' ),
    			'view_items'						=> __( 'View Publication' ),
    			'search_items'  				=> __( 'Search Publications' ),
    			'not_found'							=> __( 'No publications found' ),
    			'not_found_in_trash'		=> __( 'No publications found in the Trash' ),
    			'parent_item_colon'			=> '',
    			'menu_name'							=> 'Publications'
    		),
    		'has_archive'  	=> true,
    		'hierarchical' 	=> true,
    		'menu_icon'    	=> get_stylesheet_directory_uri() . '/lib/icons/publications.png',
    		'public'       	=> true,
    		'menu_position' => 3,
    		'rewrite'      	=> array( 'slug' => 'publication', 'with_front' => false ),
    		'supports'     	=> array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'revisions', 'genesis-seo', 'genesis-cpt-archives-settings' ),
    		'taxonomies'   	=> array( 'publication-type', 'category', 'post_tag' ),
    
    		)
    	);
    
    }
    

    I've also created the "Type" custom taxonomy in the publication custom content type.

    //* Create Publication Type custom taxonomy
    add_action( 'init', 'executive_publication_type_taxonomy' );
    function executive_publication_type_taxonomy() {
    
    	register_taxonomy( 'publication-type', 'publication',
    	array(
    		'labels' => array(
    			'name'          => _x( 'Types', 'taxonomy general name', 'executive' ),
    			'add_new_item'  => __( 'Add New Publication Type', 'executive' ),
    			'new_item_name' => __( 'New Publication Type', 'executive' ),
    		),
    		'exclude_from_search' => true,
    		'has_archive'         => true,
    		'hierarchical'        => true,
    		'rewrite'             => array( 'slug' => 'publications', 'with_front' => false ),
    		'show_ui'             => true,
    		'show_tagcloud'       => false,
    		)
    	);
    
    }

    When defining the "Publication" custom content type, I included category and post_tag in the taxonomies declaration, thinking that this would make post categories and tags available to my "Publication" custom content type. However, when I view a category, I only see posts with that category; my custom content type "publications" do not appear in the category archive page. How can I get all content types with the shared category to appear in the category archive page?

    January 20, 2015 at 10:10 pm #138158
    nkleekamp
    Member

    I found the answer on StackExchange and expanded it with a little more info from the Codex.

    For anyone else that might need it, here was my solution.

    //* Include Custom Post Types in author, category, and tag archive page
    function __set_cpt_for_archives( &$query ) {
    	$post_types = array( 'post', 'portfolio', 'publication' );
    	$archive_types = array( 'is_author', 'is_tag', 'is_category' );
    
    	foreach ( $archive_types as $key => $val ) {
    		if ( $query->$val ) {
    			$query->set( 'post_type', $post_types );
    			remove_action( 'pre_get_posts', '__set_cpt_for_archives' );
    		}
    	}
    }
    
    add_action( 'pre_get_posts', '__set_cpt_for_archives' );
    
  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble