WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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){

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






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

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

Your Answer


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.