wc_change_pre_get_terms()
Adds support to get_terms for menu_order argument.
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
wc_change_pre_get_terms( $terms_query );
- $terms_query(WP_Term_Query) (обязательный)
- Instance of WP_Term_Query.
Список изменений
С версии 3.6.0 | Введена. |
Код wc_change_pre_get_terms() wc change pre get terms WC 9.4.2
function wc_change_pre_get_terms( $terms_query ) { $args = &$terms_query->query_vars; // Put back valid orderby values. if ( 'menu_order' === $args['orderby'] ) { $args['orderby'] = 'name'; $args['force_menu_order_sort'] = true; } if ( 'name_num' === $args['orderby'] ) { $args['orderby'] = 'name'; $args['force_numeric_name'] = true; } // When COUNTING, disable custom sorting. if ( 'count' === $args['fields'] ) { return; } // Support menu_order arg used in previous versions. if ( ! empty( $args['menu_order'] ) ) { $args['order'] = 'DESC' === strtoupper( $args['menu_order'] ) ? 'DESC' : 'ASC'; $args['force_menu_order_sort'] = true; } if ( ! empty( $args['force_menu_order_sort'] ) ) { $args['orderby'] = 'meta_value_num'; $args['meta_key'] = 'order'; // phpcs:ignore $terms_query->meta_query->parse_query_vars( $args ); } }