Skip Navigation

[Resolved] Taxonomy order by Main-taxonomy; sub-taxonomy.

This support ticket is created 4 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by LennyS7960 4 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1999001

Tell us what you are trying to do?
Taxonomys are displayed desc or asc alphabetically. So for example:

ZTaxonomy1
- - ASub taxonomy1
ATaxonomy2
- - ZSub taxonomy2

Is displayed as" ASub taxonomy1, ZTaxonomy1 " and "ATaxonomy2, ZSub taxonomy2." but I need it always to display in view table and single post page inline field so that Main taxonomy is always first and sub taxonomy is 2nd = "ZTaxonomy1, ASub taxonomy1, " and "ATaxonomy2, ZSub taxonomy2."
Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1999301

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

There isn't such an option, to order the terms according to their hierarchy.

I'll admit I'm surprised this hasn't been proposed before, I don't see any internal ticket about providing such an option, although it's a sensible one, so I will create such a request and hopefully it is a setting we can add in the UI.

In the meantime I wrote a shortcode you can use.

Go to Toolset > Settings > Custom Code and add the following to a code snippet:

add_shortcode('terms', function ($atts = []) {

    // defaults
    $atts = shortcode_atts(
        array(
            'order' => 'ASC',
            'taxonomy' => ''
        ),
        $atts
    );

    $output = '';
    global $post;

    $terms = wp_get_post_terms( $post->ID, $atts['taxonomy'], [ 'orderby' => 'parent', 'order' => $atts['order'], 'fields' => 'names' ] );

    if ( is_array( $terms ) && !empty( $terms ) )
    {
        $output = implode( ', ', $terms );
    }
    return $output;
});

Then in the template of View output where you want to display terms for the current post, add a Shortcode block and insert the shortcode like so:

[terms taxonomy='taxonomy-slug' order="DESC"]

Use the relevant taxonomy slug. You can omit the order attribute to use the default 'ASC' option (which is what I think you need in your example).

#1999521

Nice! This is perfect. I too thought that it would be already implemented.