[wp-trac] [WordPress Trac] #13582: filtering via post_type + taxonomy does not work properly.
WordPress Trac
wp-trac at lists.automattic.com
Thu May 27 20:02:30 UTC 2010
#13582: filtering via post_type + taxonomy does not work properly.
--------------------------+-------------------------------------------------
Reporter: anointed | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Unassigned
Component: Post Types | Version: 3.0
Severity: normal | Keywords: post_types, taxonomies
--------------------------+-------------------------------------------------
Comment(by michaelh):
If you have registered a taxonomy called series, and for some of those
movies let's say you used "xyz" for the series.
You should be able to get all published movies assigned the series "xyz"
with this:
{{{
<?php
$args=array(
'series'=>'xyz',
'post_type' => 'movies',
'post_status' => 'publish',
'posts_per_page' => -1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent
Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query();
?>
}}}
If you are trying to get all movies that are assigned any series value,
you would need to iterate through your series terms, and get the movies in
each term...like:
{{{
<?php
$post_type = 'movies';
$tax = 'series';
$tax_terms = get_terms($tax);
if ($tax_terms) {
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
"$tax" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of '.$post_type . ' where the taxonomy '. $tax . ' is '.
$tax_term->name;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>"><?php
the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query();
}
}
?>
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/13582#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list