Support » Plugin: Genesis Grid » Multiple Custom post types

  • Resolved Bill

    (@billmcq)


    Hi Bill… REALLY struggling with trying to use this for 2 or 3 different CPT’s.

    It works great for one CPT, but when I add a second CPT in functions.php, I stop getting the correct posts being pulled. (I am using some taxonomies as well)

    For instance, if I just create a NEW EQUIPMENT CPT, and use the code below, it works great…I get the new equiptment posts in the grid, and the added taxonomies will just pull up just the catoegories of posts within that custom post type taxonomy..GOOD TO GO!

    But if I add another custom post type with the same code formula and just change the function names, It gets wonky…. the newly created 2nd CPT starts pulling all CPT’s not just its own, etc.

    Code I am using is below:
    I would GREATLY appreciate if you could shed light on this.

    //******************** Create USED Equipment  custom post type *******************************/
    add_action( 'init', 'executive_used_post_type' );
    function executive_used_post_type() {
    
    	register_post_type( 'used',
    		array(
    			'labels' => array(
    				'name'          => __( 'Used Equipment', 'executive' ),
    				'singular_name' => __( 'Used Equipment', 'executive' ),
    			),
    			'has_archive'  => true,
    			'hierarchical' => true,
    			'menu_icon'    => get_stylesheet_directory_uri() . '/lib/icons/portfolio.png',
    			'public'       => true,
    			'rewrite'      => array( 'slug' => 'used', 'with_front' => true ),
    			'supports'     => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes', 'author', 'comments' ,'genesis-layouts', 'genesis-seo' , 'genesis-cpt-archives-settings', 'trackbacks', 'revisions' ),
    			'taxonomies'   => array( 'used-equipment' ),
    
    		)
    	);
    
    }
    
    //* Create USED Type custom taxonomy
    add_action( 'init', 'executive_used_type_taxonomy' );
    function executive_used_type_taxonomy() {
    
    	register_taxonomy( 'used-equipment', 'used',
    		array(
    			'labels' => array(
    				'name'          => _x( 'Used Equipment Types', 'taxonomy general name', 'executive' ),
    				'add_new_item'  => __( 'Add Used Equipment Type', 'executive' ),
    				'new_item_name' => __( 'Used Equipment Type', 'executive' ),
    			),
    			'exclude_from_search' => true,
    			'has_archive'         => true,
    			'hierarchical'        => true,
    			'rewrite'             => array( 'slug' => 'used-equipment', 'with_front' => true ),
    			'show_ui'             => true,
    			'show_tagcloud'       => false,
    		)
    	);
    
    }
    
    /**
     * Grid Loop on Portfolio archive * @author Bill Erickson  @link https://github.com/billerickson/Genesis-Grid/wiki/Home
     */
    function be_grid_loop_on_used( $grid, $query ) {
    	 if ( is_post_type_archive( 'used' ) || is_tax( 'used-equipment' ) )
    		$grid = true;
    
        return $grid;
    }
    add_filter( 'genesis_grid_loop_section', 'be_grid_loop_on_used', 10, 2 );
    
    /***************************************** REBUILT POST TYPE ************************************************/
    
    add_action( 'init', 'executive_rebuilt_post_type' );
    function executive_rebuilt_post_type() {
    
    	register_post_type( 'rebuilt',
    		array(
    			'labels' => array(
    				'name'          => __( 'Rebuilt Equipment', 'executive' ),
    				'singular_name' => __( 'Rebuilt Equipment', 'executive' ),
    			),
    			'has_archive'  => true,
    			'hierarchical' => true,
    			'menu_icon'    => get_stylesheet_directory_uri() . '/lib/icons/portfolio.png',
    			'public'       => true,
    			'rewrite'      => array( 'slug' => 'used', 'with_front' => true ),
    			'supports'     => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes', 'author', 'comments' ,'genesis-layouts', 'genesis-seo' , 'genesis-cpt-archives-settings', 'trackbacks', 'revisions' ),
    			'taxonomies'   => array( 'rebuilt-equipment' ),
    
    		)
    	);
    
    }
    
    // Create REBUILT Type custom taxonomy
    add_action( 'init', 'executive_rebuilt_type_taxonomy' );
    function executive_rebuilt_type_taxonomy() {
    
    	register_taxonomy( 'rebuilt-equipment', 'rebuilt',
    		array(
    			'labels' => array(
    				'name'          => _x( 'Rebuilt Equipment Types', 'taxonomy general name', 'executive' ),
    				'add_new_item'  => __( 'Add Rebuilt Equipment Type', 'executive' ),
    				'new_item_name' => __( 'Rebuilt Equipment Type', 'executive' ),
    			),
    			'exclude_from_search' => true,
    			'has_archive'         => true,
    			'hierarchical'        => true,
    			'rewrite'             => array( 'slug' => 'rebuilt-equipment', 'with_front' => true ),
    			'show_ui'             => true,
    			'show_tagcloud'       => false,
    		)
    	);
    
    }
    
    /**
     * Grid Loop on Portfolio archive * @author Bill Erickson  @link https://github.com/billerickson/Genesis-Grid/wiki/Home
     */
    function be_grid_loop_on_rebuilt( $grid, $query ) {
    	 if ( is_post_type_archive( 'rebuilt' ) || is_tax( 'rebuilt-equipment' ) )
    		$grid = true;
    
        return $grid;
    }
    add_filter( 'genesis_grid_loop_section', 'be_grid_loop_on_rebuilt', 10, 2 );

    [Moderator Note: Please post code or markup between backticks or use the code button. Or better still – use a pastebin. Your posted code may now have been permanently damaged by the forum’s parser.]

    https://wordpress.org/plugins/genesis-grid-loop/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Interesting issue you’re experiencing. I am implementing this plugin with multiple custom post types and not having any problem. Sadly, I don’t have any corrective wisdom for you, but I wonder if it has to do with your code above, or a plugin conflict…

    Just a thought.

    Plugin Author Bill Erickson

    (@billerickson)

    You have the same rewrite slug for both post types, so WordPress thinks they are the same thing. Change this line:

    'rewrite'      => array( 'slug' => 'used', 'with_front' => true ),
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple Custom post types’ is closed to new replies.