WordPress: get_term() offset parameter not working

I don’t understand why the offset parameter for get_terms isn’t working. This should start from the 5th iteration excluding the 1st to 4th but still it display all the taxonomies on my end.

Here’s my code:

Read More
  $countterms = wp_count_terms( 'item_category' );
  $offset = 4;
  $number = $countterms - $offset;
  $terms = get_terms( 'item_category', array(
      'hide_empty' => true,
      'orderby'    => 'name', 
      'order'      => 'ASC',
      'exclude'    => array(145,138,110,139,140,141,130,142,144,116,143),
      'offset'     => $offset,
      'number'     => $number
  ) );

Any suggestion to my problem would greatly be appreciated.

Related posts

Leave a Reply

1 comment

  1. Here you need also to apply your exclude terms in wp_count_terms() function:

    $exclude = array(145,138,110,139,140,141,130,142,144,116,143)
    $countterms = wp_count_terms( 'item_category', array(
        // 'hide_empty' => true, // optional (see if you need it)
        'exclude' => $exclude
    ) );
    $offset = 4;
    $number = $countterms - $offset;
    $terms = get_terms( 'item_category', array(
        'hide_empty' => true,
        'orderby'    => 'name', 
        'order'      => 'ASC',
        'exclude'    => $exclude,
        'offset'     => $offset,
        'number'     => $number
    ) );
    

    wp_count_terms() function works as get_terms(), so you can apply to it your excluded terms too.

    If not, you get all list like explained in first reference below.

    References: