0

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.

  • 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
2

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.

  • Thanks,I have corrected but it still doesn't work. – BadJohnny Dec 21 '12 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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