Changing the filter category order

Problem:

How can I change the default filter category order?

Original poster

Solution:

WordPress by default doesn’t provide an order option to the categories. One way to set a custom order to your categories would be to order them by their slug. To do this, you have to open the theme’s lib/functions/portfolio.php file (for Dandelion and Anthology themes functions/portfolio.php)and in the bottom of the file within the pexeto_get_taxonomy_children function you have to change the two lines that contain the SQL queries like this:
the first line:

$res = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name, t.slug FROM $wpdb->terms as t LEFT JOIN $wpdb->term_taxonomy tt ON t.term_id=tt.term_id WHERE tt.taxonomy=%s AND tt.parent=%s ORDER BY t.slug;", $type, $parent_id));

and the second line:

$res = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name, t.slug FROM $wpdb->terms as t LEFT JOIN $wpdb->term_taxonomy tt ON t.term_id=tt.term_id WHERE tt.taxonomy=%s ORDER BY t.slug;", $type));

with this modification your categories will be ordered by slug, so by editing their slug you can change the order. One option would be to append a number like this:

1-photography
2-landscapes
3-portraits

Pexeto

Was this useful? 8