• Tushar

    (@tushar4monto)


    Hello,

    get_terms its very useful to get taxonomy terms but something is missing with arguments like.

    $tax_args = array(
        'taxonomy'    => 'sector',
        'orderby'     => 'name',
        'order'       => 'ASC',
        'fields'      => 'all',
        'hide_empty'  => true,
        'pad_counts'  => true
    );
    $terms = get_terms( $tax_args );
    
    Currently, we get sectors counts with post status draft means pad_counts also count draft  post_status count So, there is should argument parameter for we can pass,
    
    $tax_args = array(
      'taxonomy'    => 'sector',
      'orderby'     => 'name',
      'order'       => 'ASC',
      'fields'      => 'all',
      'hide_empty'  => true,
      'pad_counts'  => true,
      'post_status' => 'publish',
      'post_type'   => 'candidate'
    );
    
    $terms = get_terms( $tax_args );

    So, it will only count just publish posts count.

    Thanks & Regards
    Tushar Kataria

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m sorry get_terms() does not entirely meet your needs. It’s inevitable that WP functions cannot be all things to all people. There will always be an unmet need for some because there just isn’t that much of a need for most people. I know this is little consolation when it’s your unmet need.

    Often enough, there is a work around in such cases, though it may be more cumbersome and not immediately apparent. In this case, you can alter the SQL clauses actually used to get terms, so you can alter the query in any way you see fit, within the limits of mySQL. You can alter SQL clauses through the “terms_clauses” filter.

    Be sure to only alter the query for your specific need and not any other uses of the WP_Term_Query class that happens elsewhere. You can do so by checking for specific query vars and/or selectively adding your callback only as needed and removing it after use.

Viewing 1 replies (of 1 total)
  • The topic ‘get_terms missing arguments’ is closed to new replies.