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?

1 Answer 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

$order = $_GET['order'];
$order = 'ASC';
$categories = get_terms( 'category', array(
'orderby'    => 'name',
'order'=> $order,
) );
  • Thank you for your answer but unfortunately its not working. check out this link: tjdesigners.info/mooctracks/?post_type=courses After using each filters the url changes. Suppose I choose Begineer under Level, then the url changes to tjdesigners.info/mooctracks/… Now if I put /?order=DESC it doesnt work . Can you please tell me how to make it work? thanks
    – Ray
    Commented Sep 7, 2013 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.