WordPress.org

Ready to get started?Download WordPress

Forums

Displaying Multiple Custom Post Types Based Off Custom Taxonomy (3 posts)

  1. bsweat
    Member
    Posted 2 years ago #

    I'm having an issue with the WordPress loop in displaying 4 different custom post types based on one custom taxonomy. I need to display all of the posts (in each different post type, and the custom field info) by the category selected in the custom taxonomy. Here is the code from my functions.php

    add_action( 'init', 'create_post_type_speakers' );
    
    function create_post_type_speakers() {
    	register_post_type( 'speakers',
    		array(
    			'labels' => array(
    				'name' => __( 'Speakers' ),
    				'singular_name' => __( 'Speaker' ),
    				'add_new' => __( 'Add New' ),
    				'add_new_item' => __( 'Add New Speaker' ),
    				'edit' => __( 'Edit' ),
    				'edit_item' => __( 'Edit Speaker' ),
    				'new_item' => __( 'New Speaker' ),
    				'view' => __( 'View Speakers' ),
    				'view_item' => __( 'View Speaker' ),
    				'search_items' => __( 'Search Speakers' ),
    				'not_found' => __( 'No Speakers Found' ),
    				'not_found_in_trash' => __( 'No Speakers in  Trash' ),
    				'parent' => __( 'Parent Speaker' )
    			),
    			'supports' => array(
    				'title',
    				'author',
    				'custom-fields',
    				'page-attributes'),
    			'public' => true,
    			'show_ui' => true,
    			'publicly_queryable' => true,
    			'menu_position' => 11,
    			'hierarchical' => false,
    			'query_var' => true,
    			'rewrite' => array('slug' => 'speaker')
    		)
    	);
    }
    
    add_action( 'init', 'create_post_type_gold_sponsors' );
    
    function create_post_type_gold_sponsors() {
    	register_post_type( 'gold_sponsors',
    		array(
    			'labels' => array(
    				'name' => __( 'Gold Sponsors' ),
    				'singular_name' => __( 'Gold Sponsor' ),
    				'add_new' => __( 'Add New' ),
    				'add_new_item' => __( 'Add New Gold Sponsor' ),
    				'edit' => __( 'Edit' ),
    				'edit_item' => __( 'Edit Gold Sponsor' ),
    				'new_item' => __( 'New Gold Sponsor' ),
    				'view' => __( 'View Gold Sponsors' ),
    				'view_item' => __( 'View Gold Sponsor' ),
    				'search_items' => __( 'Search Gold Sponsors' ),
    				'not_found' => __( 'No Gold Sponsors Found' ),
    				'not_found_in_trash' => __( 'No Gold Sponsors in  Trash' ),
    				'parent' => __( 'Parent Sponsor' )
    			),
    			'supports' => array(
    				'title',
    				'author',
    				'custom-fields',
    				'page-attributes'),
    			'public' => true,
    			'show_ui' => true,
    			'publicly_queryable' => true,
    			'menu_position' => 11,
    			'hierarchical' => false,
    			'query_var' => true,
    			'rewrite' => array('slug' => 'gold-sponsors')
    		)
    	);
    }
    
    add_action( 'init', 'create_post_type_host_sponsors' );
    
    function create_post_type_host_sponsors() {
    	register_post_type( 'host_sponsors',
    		array(
    			'labels' => array(
    				'name' => __( 'Host Sponsors' ),
    				'singular_name' => __( 'Host Sponsor' ),
    				'add_new' => __( 'Add New' ),
    				'add_new_item' => __( 'Add New Host Sponsor' ),
    				'edit' => __( 'Edit' ),
    				'edit_item' => __( 'Edit Host Sponsor' ),
    				'new_item' => __( 'New Host Sponsor' ),
    				'view' => __( 'View Host Sponsors' ),
    				'view_item' => __( 'View Host Sponsor' ),
    				'search_items' => __( 'Search Host Sponsors' ),
    				'not_found' => __( 'No Host Sponsors Found' ),
    				'not_found_in_trash' => __( 'No Host Sponsors in  Trash' ),
    				'parent' => __( 'Parent Sponsor' )
    			),
    			'supports' => array(
    				'title',
    				'author',
    				'custom-fields',
    				'page-attributes'),
    			'public' => true,
    			'show_ui' => true,
    			'publicly_queryable' => true,
    			'menu_position' => 11,
    			'hierarchical' => false,
    			'query_var' => true,
    			'rewrite' => array('slug' => 'host-sponsors')
    		)
    	);
    }
    
    add_action( 'init', 'create_post_type_title_sponsors' );
    
    function create_post_type_title_sponsors() {
    	register_post_type( 'title_sponsors',
    		array(
    			'labels' => array(
    				'name' => __( 'Title Sponsors' ),
    				'singular_name' => __( 'Title Sponsor' ),
    				'add_new' => __( 'Add New' ),
    				'add_new_item' => __( 'Add New Title Sponsor' ),
    				'edit' => __( 'Edit' ),
    				'edit_item' => __( 'Edit Title Sponsor' ),
    				'new_item' => __( 'New Title Sponsor' ),
    				'view' => __( 'View Title Sponsors' ),
    				'view_item' => __( 'View Title Sponsor' ),
    				'search_items' => __( 'Search Title Sponsors' ),
    				'not_found' => __( 'No Title Sponsors Found' ),
    				'not_found_in_trash' => __( 'No Title Sponsors in  Trash' ),
    				'parent' => __( 'Parent Sponsor' )
    			),
    			'supports' => array(
    				'title',
    				'revisions',
    				'author',
    				'editor',
    				'custom-fields',
    				'page-attributes'),
    			'public' => true,
    			'show_ui' => true,
    			'publicly_queryable' => true,
    			'menu_position' => 11,
    			'hierarchical' => false,
    			'query_var' => true,
    			'rewrite' => array('slug' => 'title-sponsor')
    		)
    	);
    }
    
    function tax_conference_init() {
    	$labels = array(
        'name' => _x( 'Conferences', 'taxonomy general name' ),
        'singular_name' => _x( 'Conference', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Conferences' ),
        'all_items' => __( 'All Conferences' ),
        'parent_item' => __( 'Parent Conference' ),
        'parent_item_colon' => __( 'Parent Conference:' ),
        'edit_item' => __( 'Edit Conference' ),
        'update_item' => __( 'Update Conference' ),
        'add_new_item' => __( 'Add New Conference' ),
        'new_item_name' => __( 'New Conference Name' ),
      );
    	// create a new taxonomy
    	register_taxonomy(
    		'conferences',
    		array('speakers', 'sponsors', 'gold_sponsors', 'host_sponsors', 'title_sponsors'),
    		array(
    			'label' => __('Conferences'),
    			'hierarchical' => true,
    			'rewrite' => array('slug' => 'conferences'),
    			'labels' => $labels
    		)
    	);
    }
    add_action( 'init', 'tax_conference_init' );

    I have ran through about a dozen different querys to display the custom post types properly, to no avail. can someone point me in the right direction of how to display custom meta field information for multiple custom post types based upon a query of a taxonomy? I feel like I may be missing a few things...

  2. hoss9009
    Member
    Posted 2 years ago #

    Me too.

  3. ellp
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.