add_filter( ‘get_terms_args’, ‘custom_terms_orderby’ );
function custom_terms_orderby( $args ) {
if ( isset( $args[‘taxonomy’] ) && $args[‘taxonomy’] == ‘category’ ) {
$args[‘orderby’] = ‘term_order’;
}
return $args;
}
add_filter( ‘terms_clauses’, ‘custom_terms_orderby’, 10, 3 );
function custom_terms_orderby( $clauses, $taxonomies, $args ) {
global $wpdb;
// Проверяем, что сортировка требуется для таксономии category
if ( in_array( ‘category’, $taxonomies ) ) {
// Изменяем сортировку на основе порядка term_order
$clauses[‘orderby’] = «$wpdb->terms.term_order ASC»;
}
return $clauses;
}
add_filter( ‘get_terms_orderby’, ‘custom_terms_orderby’, 10, 3 );
function custom_terms_orderby( $orderby, $args, $taxonomies ) {
// Проверяем, что сортировка требуется для таксономии category
if ( in_array( ‘category’, $taxonomies ) ) {
$orderby = ‘term_order’; // Сортировка по порядку term_order
}return $orderby;
}
add_filter(‘get_terms_args’, ‘custom_category_order’, 10, 2);
function custom_category_order($args, $taxonomies) {
if (in_array(‘category’, $taxonomies) && !isset($args[‘orderby’])) {
$args[‘orderby’] = ‘term_order’; // Сортировка по порядку term_order
$args[‘order’] = ‘ASC’; // Порядок сортировки (ASC — по возрастанию)
}
return $args;
}
add_filter(‘get_terms_args’, ‘custom_category_order’, 10, 2);
function custom_category_order($args, $taxonomies) {
if (in_array(‘category’, $taxonomies) && !isset($args[‘orderby’])) {
$args[‘orderby’] = ‘term_order’; // Сортировка по порядку, установленному в административной панели
$args[‘order’] = ‘ASC’; // Порядок сортировки (ASC — по возрастанию)
}
return $args;
}