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

how can i get posts retrieved by tags, I want to count them. The code i want to use in tabs.

Ex: Movies(3) , Articles(15)

Movies and Articles are Tabs.

I know how to retrieve the count of posts from a custom field.

$related_posts = get_field( 'tags' );
$count = 0;
if ( !empty( $related_posts ) ) {
    $count = count( $related_posts );
echo $count;

How can I count the post retrieved by tags. Ex: Tag Will Smith - this tag has 6 news

EX: Articles on the page (6)

6 - mean there are 6 articles containing the tag Will Smith

How can I count the articles retrieved.

PS: This is how I retrieve the articles.

$orig_post = $post;
        global $post;
        $tags = wp_get_post_tags($post->ID);

        if ($tags) {
            $tag_ids = array();
            foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
                'tag__in' => $tag_ids,
                'post__not_in' => array($post->ID),
                'post_type'=> 'stiri',
                'posts_per_page'=>20, // Number of related news that will be shown.

$recentPosts = new WP_Query($args);
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
share|improve this question

WP_Query has a post_count property: codex.

$recentPosts = new WP_Query($args);
$count = $recentPosts->post_count;
share|improve this answer
not working, i do not use the code in the Querry, i use in tabs and the tabs are outside the querry... – Batman Apr 9 '13 at 23:35
You made no mention of tabs in your question. Please revise it accordingly. – vancoder Apr 9 '13 at 23:38
edited vancoder, sorry for that. – Batman Apr 9 '13 at 23:43

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.