Order custom Taxomony alphabetically and reversal after clicking a button?

I made a custom type named foods and a taxonomy named fruits. I want to order the fruits name alphabetically ( A-Z ) on clicking a button and then clicking on it again it will show Z-A order.

Can you tell me how to do it please?

Related posts

1 comment

  1. Pass order parameter in url on click on link like /?order=DESC or if you are using a button then it must be submitting a form with order field value change GET to POST and field name

    if(isset($_GET['order'])){
    $order = $_GET['order'];
    }
    else{
    $order = 'ASC';
    }
    $categories = get_terms( 'category', array(
    'orderby'    => 'name',
    'order'=> $order,
    ) );
    

Comments are closed.