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'm looking to count how many post live within the custom post type called "videos", but only the ones from the category called "work".

<?php $count_posts = wp_count_posts('videos'); echo $count_posts->publish; // ?>

How can I adjust the above code to accomplish this?

Thanks!

share|improve this question
add comment

2 Answers

Found a solution.

<?php $posts = get_posts('post_type=videos&category=4'); 
$count = count($posts); 
echo $count; 
?>
share|improve this answer
add comment

An alternative solution using WP_Query would be:

$args = array(
  'cat' => 4,
  'post_type' => 'videos'
);
$the_query = new WP_Query( $args );
echo $the_query->found_posts;
share|improve this answer
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.