WordPress.org

Ready to get started?Download WordPress

Forums

3.0 custom taxonomies registered to multiple post_types question (2 posts)

  1. Anointed
    Member
    Posted 4 years ago #

    I run the following function in my themes functions.php file:

    register_taxonomy('series', array('post','page','sermons','podcasts'),
    array(
    	'labels' =>array(
    	    'name' => _x('series', 'taxonomy general name'),
    	    'singular_name' => _x( 'series', 'taxonomy singular name'),
    	    'search_items' => __( 'Search Series' ),
    	    'popular_items' => __( 'Popular Series' ),
    	    'all_items' => __( 'All Series' ),
    	    'parent_item' => __( 'Parent Series' ),
    	    'parent_item_colon' => __( 'Parent Series:' ),
    	    'edit_item' => __( 'Edit Series' ),
    	    'update_item' => __( 'View Series' ),
    	    'add_new_item' => __( 'Add New Series' ),
    	    'new_item_name' => __( 'New Series Name' ),
        	    ),
       	 'hierarchical' => true,
       	 'show_ui' => true,
       	 'query_var' => true,
       	 'rewrite' => array( 'slug' => 'series' ),
       	 )
       	 );

    As you can see in above, the tax 'sermons' is attached to (posts, pages, sermons, podcasts)

    That works perfectly and as expected.

    Where I am stuck and need help:

    I have an 'archive' listing page for the tax 'series'. On that page, all post_types are returned for the tax 'series' in the order they were posted.

    example:
    test site

    The reason you always see what seems like duplicate posts, is because every time I create a new sermon, I also create a new matching podcast. Both the sermon and podcast contain the same tax 'series'.

    What I want to accomplish:

    I want to separate out the displayed information via post_type. This means the archive page for tax 'series' would look like this:

    sermons:
    --sermon 1
    --sermon 2
    --sermon 3
    podcasts:
    --podcast 1
    --podcast 2
    --podcast 3
    posts:
    --post 1
    --post 2
    --post 3
    pages:
    --page 1
    --page 2
    --page 3

    What I need to do this:

    I need some type of example wp_query that would return each post_type with pagination, so that I can create 4 loops, 1 for each post_type that belongs to tax 'series'.

    I have searched high n' low, but to date I have not seen even a hint of an example of how to do this anywhere.

    I do realize this is getting beyond the normal wp operations, and relatively advanced, but I can handle it. Just need some starting pointers.

    It's possible that I may end up figuring out the multi-loops issue, but adding in pagination on a per post_type within the archive page, is going to be really really interesting.

    by any chance is anyone willing to help me tackle this issue?

  2. scribu
    Member
    Posted 4 years ago #

    This should work:

    foreach ( array('sermon', 'podcast') as $post_type ) {
        query_posts(array('post_type' => $post_type, 'series' => 'x'));
    
        while ( have_posts() ) : the_post();
            // display code
        endwhile;
    }

    I'm not sure what kind of pagination would make sense with this layout, though.

Topic Closed

This topic has been closed to new replies.

About this Topic