wp_query order by term group (3 posts)

  1. cellobrutos
    Posted 5 years ago #

    Hi everybody,

    I am working on a new theme right now, where I need some category ordering done.
    On one of the templates, I would need the following code to work:
    $custom_query = new WP_Query( array ( 'cat' => $catid , 'orderby' => 'term_group' ))

    It *has* to work with term_group somehow, and yes I've tried quite a few category order plugins, which don't really work for what I need to do - my categories are ordered, but I just need to display the post they contain in the order of the categories.

    Thanks in advance, I'm really stuck on this one...


  2. Marie-Aude
    Posted 5 years ago #

    term_group is not used by wordpress default : the value is 0 even for hierarchicals taxonomies. So it's normal it has no effect

  3. wlindley
    Posted 4 years ago #

    The only place where WP currently sets term_group is in wp_insert_term() in wp-includes/taxonomy.php. The code there only runs when you specify an alias_of parameter when adding a term. In that case, the value of alias_of should be the slug of an existing term in the same taxonomy. Both the existing term and the new term, will be given the same term_group starting with 1, regardless of the term_id of the original term... if the original term did not have a term_group assigned, a new one will be created.

    All of that pretty much squelches any other use of the term_group column.

    It would be nice if terms had a sort_order column; that would do what you want, as well as letting us re-order built-in terms like Categories. Perhaps it could be added.

Topic Closed

This topic has been closed to new replies.

About this Topic