Support » Fixing WordPress » get_terms orderby

  • Hi,
    I am using get_terms and attempting to use orderby NAME.

    I have 2 terms with name & slug & id as follows:
    ([name] => 1 Tog [slug] => 1 [term_id] => 47 …)
    ([name] => 2.5 Togs [slug] => 2-5 [term_id] => 48 …)

    I want to list these by name, so use
    $terms = get_terms( sanitize_title($name), array(‘orderby’ => ‘name’) );
    (or without name as it should be the default)
    This gives me
    2.5 Tog
    1 Tog

    Which as far as i can see is the wrong order?

    If I use orderby => slug or ID, then I get the correct order (1 Tog, 2.5 Togs).

    I have tried a direct SQL select:
    FROM wp_terms WHERE term_id >46 AND term_id <49 ORDER BY name
    which gives me the correct (1 Tog, 2.5 Togs).

    Is there a reason why it wouldn’t work with the get_terms, using orderby name?


  • The topic ‘get_terms orderby’ is closed to new replies.