[wp-hackers] getting post counts for multiple tags

Dion Hulse (dd32) wordpress at dd32.id.au
Mon May 21 04:02:41 UTC 2012


I missed the fact you were doing it on the Tag page, so yes, Using
$wp_query->post_count is the right way to do it (And the last step in
my suggestion:))

On 21 May 2012 14:00, Chris McCoy <chris at lod.com> wrote:
> Actually I just used $wp_query->post_count;
>
> Works fine, on the tag.php template
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com
> [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Dion Hulse
> (dd32)
> Sent: Sunday, May 20, 2012 8:12 PM
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] getting post counts for multiple tags
>
> In order to do that, you'd have to make a new WP_Query, query for the tag
> intersections, probably limit it to 1 post, and look at the total count it
> returns. You could save memory/query time by only asking for the ids of the
> posts too.
> You'd want to store the counts in a cache somehow, a transient would
> probably suit best.
>
> Of course, that's just my suggestion without resolving to using custom SQL.
>
> On 21 May 2012 01:14, Chris McCoy <chris at lod.com> wrote:
>> What would be the best way to go about, finding the amount of posts
>> for multiple tags.
>>
>> I will be using it on a tag archive page.
>>
>>        $tag_count = get_term_by('name',
>> get_query_var('tag'),'post_tag');
>>        echo $tag_count->count;
>>
>> this works fine for one tag, but I want to check via tag1,tag2,tag3
>> and
>> tag1+tag2+tag3 how many posts match those
>>
>>
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list