ccmanz ccmanz - 4 months ago 6
PHP Question

How to offset term result?

I have a function that displays the categories of a custom taxonomy. I want this function to start at the 5th onwards and excludes the 1st to 4th category. I'm using get_term using the offset parameter and it doesn't work. Any ideas? Here's my code:

$terms = get_terms( 'item_category', array(
'hide_empty' => true,
'orderby' => 'name',
'order' => 'ASC',
'offset' => 4
) );

Any help would be appreciated. Thanks!


This should work (see the reference):

$countterms = wp_count_terms( 'item_category' );
$offset = 4;
$number = $countterms - $offset;
$terms = get_terms( 'item_category', array(
    'hide_empty' => true,
    'orderby'    => 'name', 
    'order'      => 'ASC',
    'offset'     => $offset,
    'number'     => $number,
) );

Reference: get_terms offset working? [SOLVED]