Custom Ordering Taxonomy Terms by Custom Field Meta Value

To order taxonomy terms by a meta value (e.g., topic_order), use WP_Term_Query because get_terms() doesn’t natively support ordering by term meta.

I know there is two native way to do it but static way is static and dynamic way doesnt work properly it is buggy.. thats why I just used custom query.

this is for bricks;

return [  
    'taxonomy'   => 'codex-topic', 
    'hide_empty' => false,
    'meta_key'   => 'topic_order',
    'orderby'    => 'meta_value_num',
    'order'      => 'ASC'
];

This is for native php WordPress WP_Term_Query if you need it;

$args = array(
    'taxonomy'   => 'codex-topic', 
    'hide_empty' => false,
    'meta_key'   => 'topic_order',
    'orderby'    => 'meta_value_num', 
    'order'      => 'ASC', 
);

$term_query = new WP_Term_Query($args);

if (!empty($term_query->terms) && !is_wp_error($term_query->terms)) {
    foreach ($term_query->terms as $term) {
        echo '<p>' . esc_html($term->name) . '</p>';
    }
}

Upcoming Course

I am planning a professional WordPress and Bricks Builder course. If you are Interested register to this newsletter.