Support » Plugins » get_terms() orderby term meta?

  • Resolved MACscr

    (@macscr)


    I have query setup like so:

    $taxonomy = 'media_archive_categories';
    $parent = 135;
    $args = array(	'taxonomy' => $taxonomy,
    				'orderby' => 'id',
    				'order' => 'DESC',
    				'parent' => $parent,
    				'hide_empty' => true,
    				'number' => 9
    			);
    $terms = get_terms($args); // Get all terms of a taxonomy

    I would though like to orderby a meta field named ‘media_archive_category_date’ that has a format of ‘Y-m-d H:i:s’ (normal WP date format). Any ideas how to do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter MACscr

    (@macscr)

    Ha, looks to be as simple as:

    <?php
    
    $taxonomy = 'media_archive_categories';
    $parent = 135;
    $args = array(	'taxonomy' => $taxonomy,
    				'parent' => $parent,
    				'meta_key' => 'media_archive_category_date',
    				'orderby' => 'meta_value',
    				'order' => 'DESC',
    				'hide_empty' => true,
    				'number' => 9
    			);
    $terms = get_terms($args); // Get all terms of a taxonomy
    ?>

    Thanks very much for this solution, the official documentation is very bad about that.

    • This reply was modified 7 years, 5 months ago by alphonix.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_terms() orderby term meta?’ is closed to new replies.