Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created March 2, 2021 00:10
Show Gist options
  • Save tripflex/52c89f87416068cfff5deb40a77bba06 to your computer and use it in GitHub Desktop.
Save tripflex/52c89f87416068cfff5deb40a77bba06 to your computer and use it in GitHub Desktop.
Custom taxonomy sort order args for WP Job Manager Search and Filtering
<?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;
}
@tripflex
Copy link
Author

tripflex commented Mar 2, 2021

@tripflex
Copy link
Author

tripflex commented Mar 2, 2021

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