Reputation: 7481
I'm trying to display posts from a custom post type called portfolio using the code below and then filter the result by category, I have tried putting - category_name , catid, portfolio_category in the array
and have had a look around the forums and tried a few things but cant seem to get it to work , it either displays nothing or all the post from all categories.
<?php
$args=array(
'post_type' => 'portfolio',
'post_status' => 'publish',
'posts_per_page' => 7,
'caller_get_posts'=> 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(); // Restore global post data stomped by the_post().
?>
The registered taxonomy is portfolio_category, any help on this would be appreciated , many thanks
Upvotes: 1
Views: 1633
Reputation: 7481
After trying a few things this is how i got it to work using the 'tax_query' hope this helps someone...
<?php
$args = array(
'post_type'=>'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'slug',
'terms' => 'solutions'
)
)
);
$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 the_excerpt()?>
<?php echo get_the_post_thumbnail($post->ID, array(50,50)); ?>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
Upvotes: 1
Reputation: 1831
You could try to call the the category as a custom taxonomy:
'portfolio_cat' => 'name_of_your_category'
Upvotes: 2