• I’m trying to get the post count of 10 of hundreds of tags. At first I thought about using get_terms, but getting the terms of all the tags takes way too much time. So I’m trying to pass the args of the tag slugs. I’ve tried multiple ways to set up the array, but none seem to work.

    I’ve tried a few things:

    $args= array('tag__in' => array('1', '3', '5'));
    $alltags = get_terms('post_tag', $args);

    That just locks the page up.

    I’ve tried this as well:

    $args = array(
      'slug'=>array('slug1', 'slug2', 'slug3'));
    $alltags = get_terms('post_tag', $args);

    And I’ve tried different variations of each.

    Any thoughts on how to pull the post count on a set of tags? I could do multiple get_terms with each slug but I’m trying to have 1 database pull and not 10. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter gcarson

    (@gcarson)

    I guess this isn’t possible?

    As a workaround, I’ll have to set up a cron job get the info with multiple get_terms calls and put the results in a database. Then, each time a page is called I can just do 1 DB call to this instead up multiple get_terms calls each time.

    Hope that makes sense.

    Were you able to find a solution for this?

    Call get_terms and add the term counts up.

    $myterms = get_terms( 'post_tag', 'include=1,2,3');
    $postcount = 0;
    foreach( $myterms as $term )
        $postcount = $postcount + $term->count;
    echo $postcount;

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Post Count for Multiple Tags’ is closed to new replies.