Answer the question
In order to leave comments, you need to log in
How to sort array of taxonomy terms by field value?
Good evening!
I get taxonomy terms.
add_action('init', 'get_proizv_terms');
function get_proizv_terms() {
$terms = get_terms( array(
'hide_empty' => 0,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'taxonomy' => 'pa_obem-resivera-l',
'pad_counts' => 1
));
}
Answer the question
In order to leave comments, you need to log in
With Anatoly's help, I came up with a simple solution.
function attrName_to_termMetaOrder() {
$terms = get_terms(array(
'hide_empty' => 0,
'order' => 'ASC',
'taxonomy' => 'pa_proizvoditelnost',
'pad_counts' => 1
));
if (!empty($terms) && !is_wp_error($terms)){
foreach ($terms as $term) {
update_term_meta($term->term_id, 'order_pa_proizvoditelnost', intval($term->name), "");
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question