Method #1 – Modifying the query arguments
If we want to modify the term order for the schedule_day_taxonomy
term checklist, on the single schedule
cpt edit screen, then we can use the following setup:
add_action( 'load-post.php', function()
{
add_filter( 'wp_terms_checklist_args', 'wpse_terms_checklist_args' );
} );
function wpse_terms_checklist_args( $args )
{
// Target the 'schedule' custom post type edit screen
if( 'schedule' === get_current_screen()->id )
add_filter( 'get_terms_args', 'wpse_terms_args', 10, 2 );
return $args;
}
function wpse_terms_args( $args, $taxonomies )
{
// Target the 'all' tab in the 'schedule_day_taxonomy' terms check list
if(
isset( $args['get'] )
&& 'all' === $args['get']
&& isset( $taxonomies[0] )
&& 'schedule_day_taxonomy' === $taxonomies[0]
) {
// Modify the term order
$args['orderby'] = 'ID'; // <-- Adjust this to your needs!
$args['order'] = 'ASC'; // <-- Adjust this to your needs!
// House cleaning - Remove the filter callbacks
remove_filter( current_filter(), __FUNCTION__ );
remove_filter( 'wp_terms_checklist_args', 'wpse_terms_checklist_args' );
}
return $args;
}
Another possibility would be to combine this into a single get_terms_args
filter callback.
To get the following day order:
Sun, Mon, Tue, Wed, Thu, Fri, Sat
we could modify the corresponding term slugs and use:
// Modify the term order
$args['orderby'] = 'slug';
$args['order'] = 'ASC';
Method #2 – Re-ordering the query results
If we don’t want to modify the slug, then here’s another approach.
We can re-order the resulting terms array, in the same order as the localized weekdays.
add_filter( 'wp_terms_checklist_args', function( $args )
{
add_filter( 'get_terms', 'wpse_get_terms', 10, 3 );
return $args;
} );
function wpse_get_terms( $terms, $taxonomies, $args )
{
if( isset( $taxonomies[0] )
&& 'schedule_day_taxonomy' === $taxonomies[0]
&& 'schedule' === get_current_screen()->id
) {
$newterms = [];
foreach( (array) $GLOBALS['wp_locale']->weekday as $day )
{
foreach( (array) $terms as $term )
{
if( $term->name === $day )
$newterms[] = $term;
}
}
remove_filter( current_filter(), __FUNCTION__ );
if( 7 === count( $newterms ) )
$terms = $newterms;
}
return $terms;
}
We could also replace
$GLOBALS['wp_locale']->weekday
with a custom weekdays array, ordered in a custom way.
Here’s the English version:
and here’s the Icelandic version:
Method #3 – Custom SQL ordering
We could modify the SQL ordering with the get_terms_orderby
filter, with a CASE/WHEN/THEN
setup.
Hopefully you can adjust this to your needs.