Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use the following code to get portfolio type posts from category id, but it doesn't work.

$args = array( 'numberposts' => $items, 'post_type'=>'portfolio','orderby' => 'date','order'=>'DESC','category' => 5 );
$posts = get_posts($args);
foreach($posts as $post){
    setup_postdata($post);
    $return_html='......';
}

however,if I leave the category id empty, it' fine and will show all categories posts. I'm sure that there are many posts under category 5.

Thanks in advance.

share|improve this question
    
Did you register_taxonomy_for_post_type() or otherwise enable support for the category taxonomy for the portfolio post type? –  Chip Bennett Dec 20 '12 at 0:29
    
Yes,I did that. –  BadJohnny Dec 20 '12 at 0:45
add comment

1 Answer 1

It's

'post_date'

not

'date'

so

$args = array( 'numberposts' => $items, 'post_type'=>'portfolio','orderby' => 'post_date','order'=>'DESC','category' => 5 );
$posts = get_posts($args);
foreach($posts as $post){
    setup_postdata($post);
    $return_html='......';
}

Should fix you up.

share|improve this answer
    
Thanks,I have corrected but it still doesn't work. –  BadJohnny Dec 21 '12 at 5:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.