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.

2
  • Did you register_taxonomy_for_post_type() or otherwise enable support for the category taxonomy for the portfolio post type? Dec 20, 2012 at 0:29
  • Yes,I did that.
    – BadJohnny
    Dec 20, 2012 at 0:45

1 Answer 1

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.

1
  • Thanks,I have corrected but it still doesn't work.
    – BadJohnny
    Dec 21, 2012 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.