Skip Navigation

[Resolved] Taxonomy Order

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.

This topic contains 6 replies, has 3 voices.

Last updated by Jim 4 years, 2 months ago.

Assigned support staff: Minesh.

Author
Posts
#525513
2017-05-17_21-51-37.jpg

I am trying to: Control the order of Taxonomy output.

I visited this URL: hidden link (not public but can make if needed)

I expected to see: Primary then secondary taxonomy items.

Instead, I got: Alphabetical order taxonomy output.

https://toolset.com/forums/topic/display-wpv-post-taxonomy-and-hierarchical-taxonomies/

I tried the solution presented here but it doesn't output anything. Not sure why. Can you help me debug this?

#525586

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The solution link you shared with me belongs to the solution to display taxonomy term attached to post in correct order. Do you want same? If yes - I need to check how do you implement on your install.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#526243

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I changed the code in your functions.php file as given under and I can see the code is returning terms. Is this your expected output?

function list_hierarchical_terms($atts) {
    global $post;
     
     
    $taxonomy = $atts['taxonomy']; // change this to your taxonomy
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=none");
         
    }
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');

If no - Could you please show me text case example and remove unwanted content from view's loop output, as it confusing.

#526286
2017-05-19_11-42-23.jpg

Thank you for all your help so far, it is very close! I was a little unclear in my original request, sorry about that.

Here's the example. hidden link This page only has two things: The shortcode output, and my notes on ideal display conditions and an example.

The preferred display would output like this: Portland, OR

So that would be Child, then Parent, as text only, with no trailing separator.

The taxonomy is set up like this:
State
-City
e.g.
TX
-Houston

I don't know if it helps at all, but I did make the City the "primary" taxonomy item for each affected post. I took a screenshot to show what I'm referring to.

#526921

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've modified the code in your functions.php as given under:

function list_hierarchical_terms($atts) {
    global $post;
    
    $taxonomy = $atts['taxonomy']; // change this to your taxonomy
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "names", "orderby"=>"term_id","order"=>"DESC") );
    if( $terms ) {
	return join(", ",$terms);
                
    }
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');

Now - on your test page when you check you will get your desired output:
=> hidden link

#528071

Heeeeey, that works!

Sorry I didn't confirm this sooner. I must have missed the email. I really appreciate you taking the time to help out with this!

#1510151

Jim

I have a similar problem but I cannot use short codes because I use a view to display the taxonomy.

Is there a way to make this work inside a view?