d before calculating. if ( $per_page > 0 && ( count( $objects ) === $per_page || $page > 1 ) ) { $term_count = $this->get_term_count( $taxonomy, $prepared_args ); $response = ( new Pagination() )->add_headers( $response, $request, $term_count, ceil( $term_count / $per_page ) ); } return $response; } /** * Get count of terms for current query. * * @param string $taxonomy Taxonomy to get terms from. * @param array $args Array of args to pass to wp_count_terms. * @return int */ protected function get_term_count( $taxonomy, $args ) { $count_args = $args; unset( $count_args['number'], $count_args['offset'] ); return (int) wp_count_terms( $taxonomy, $count_args ); } }