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.

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.

<?php
$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;
            $args=array(
                '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.
                'caller_get_posts'=>1

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

1 Answer

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
1  
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
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.