loop – How to add pagination in Terms

Question

Hello on my website I have created a page where it will show all of the Woo Commerce tags in the store in list format. The problem here is that I am unable to paginate them. I have tried paginate_links function too but that’s not working. Here is my shortcode which I created

function showalltags(){
    $terms = get_terms(
    array( 
        'hide_empty' => true,
        'taxonomy' => 'product_tag',
    ) 
        );
$html="<ul class="post_tags">";
if($terms){
    foreach($terms as $term){
        $term_link = get_term_link( $term->term_id, 'product_tag' );
        $html .= "<li><a href="https://wordpress.stackexchange.com/questions/388606/" . $term_link . "" title="" . $term->name . " Tag" class="" . $term->slug . "">" . $term->name . "</a></li>";
    }
}
$html .= "</ul>";
echo $html;
}
add_shortcode('product_alltags','showalltags');

in progress 0
Ashish Jat 5 months 2021-05-23T18:27:04-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-05-30T08:51:05-05:00

    get_terms() doesn’t support pagination. However, you can achieve this with number and offset parameter. Also, you will need to count the max number of pages which is easily calculable by counting total and dividing by number parameter. Pass those data using get variable to the links.

Leave an answer

Browse
Browse