I have done a lot of research into this and it appears that not too long ago this was not possible.
Basically, I have custom post types including Review, Feature & News that share the taxonomy of Artist. I would like my taxonomy-artist page to be organized as follows with separate loops for each post type:
ARTIST NAME
Reviews
// list posts
Features
// list posts
News
// list posts
This issue was discussed [[LINK href="http://core.trac.wordpress.org/ticket/13582"]]here[[/LINK]] at Wordpress Trac and it was decided that it was unsupported. Later they marked the issue as resolved [[LINK href="http://core.trac.wordpress.org/changeset/15850"]]here[[/LINK]].
Thanks in advance for your answers.
Ivaylo Draganov answers:
Hello,
it seems possible to me. I've not tested it but try something along the lines of:
<?php
$args = array();
$args['posts_per_page'] = 5;
$args['tax_query'] = array(
array(
'taxonomy' => 'artist', // taxonomy
'field' => 'id' // term field to match against
'terms' => get_queried_object_id() // get term ID from $wp_query
)
);
$args['post_type'] = 'reviews'; // set post type
query_posts($args); // run query
// insert loop here
$args['post_type'] = 'features';
query_posts($args);
// insert loop here
$args['post_type'] = 'news';
query_posts($args);
// insert loop here
wp_reset_query();
Jeremy Phillips comments:
Thank you, although I apologize for being a php novice and I'm not sure that I'm implementing your code correctly.
Although, when I attempt it, I'm getting an error from this line:
'terms' => get_queried_object_id()
Would you be able better idea of how to integrate this?
Thanks
Ivaylo Draganov comments:
Yes, there was a minor error, a comma was missing and that produced a parse error:
'field' => 'id', // term field to match against
If PHP says something like "Parse error: Unexpected...." that means there's a syntax error - missing comma, dot or bracket or one too much. The good thing is that these errors are easy to catch.
Yesterday I came up with a different solution - to use built-in nav menus and a custom walker (a custom function for displaying the menu). It's a much more flexible solution, because you'll be able to manage menus from the WP backend without touching PHP. But it requires a little more work to set up.
After all it depends on your particular needs and whether you're happy with the current solution.
AdamGold answers:
Yes, iv.draganov has an error in his code (I hope you don't mind I fix it):
<?php
$args = array();
$args['posts_per_page'] = 5;
$args['tax_query'] = array(
array(
'taxonomy' => 'artist', // taxonomy
'field' => 'id', // term field to match against
'terms' => get_queried_object_id(), // get term ID from $wp_query
)
);
$args['post_type'] = 'reviews'; // set post type
query_posts($args); // run query
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<div class="post">
<!-- Display the Title as a link to the Post's permalink. -->
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</div> <!-- closes the first div box -->
<?php
endwhile; endif;
$args['post_type'] = 'features';
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<div class="post">
<!-- Display the Title as a link to the Post's permalink. -->
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</div> <!-- closes the first div box -->
<?php
endwhile; endif;
$args['post_type'] = 'news';
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<div class="post">
<!-- Display the Title as a link to the Post's permalink. -->
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</div> <!-- closes the first div box -->
<?php
endwhile; endif;
wp_reset_query();
Replace the DIVs with your actual post structure.