Created
March 2, 2021 00:10
-
-
Save tripflex/52c89f87416068cfff5deb40a77bba06 to your computer and use it in GitHub Desktop.
Custom taxonomy sort order args for WP Job Manager Search and Filtering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'search_and_filtering_get_taxonomy_data_options_args', 'smyles_sf_custom_tax_ordering' ); | |
function smyles_sf_custom_tax_ordering( $args ) { | |
$args['orderby'] = 'term_id'; | |
return $args; | |
} |
This snippet basically allows the ordering to be handled by the main get_terms() function, which can be handled by something like this plugin:
https://wordpress.org/plugins/simple-taxonomy-ordering/
This filter can also be used just to set your own custom ones.
Here's how the filter is called:
$args = apply_filters( 'search_and_filtering_get_taxonomy_data_options_args', array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'order' => 'ASC',
'orderby' => 'name',
'value_field' => $is_slug_taxonomy ? 'slug' : 'term_id',
));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of removing sorting:
https://gist.github.com/tripflex/b2cbf8b2c7a35d7736e048865276b2b3