Skip Navigation

[Resolved] Parent tag first with children subsequently

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 7 replies, has 2 voices.

Last updated by lesleyA 1 year, 10 months ago.

Assisted by: Waqar.

Author
Posts
#2374655
Screen Shot 2022-05-31 at 18.42.45.png

Tell us what you are trying to do?
I'm using Fields and Text to display a hierarchical taxonomy. The ordering is alphabetical which means that the parent tag isn't at the front of the list.

In the image attached, "HR" is the parent, and needs to be ahead of the others.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2375289

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

To show the post's taxonomy terms ordered by the 'parent', you'll need a custom shortcode:


add_shortcode( 'get_terms_custom_order', 'get_terms_custom_order_func');
function get_terms_custom_order_func($atts) {
	$a = shortcode_atts( array(
		'id' => '',
		'type' => '',
		'orderby' => '',
		'order' => '',
		'sep' => ''
	), $atts );

	$terms = wp_get_post_terms( $a['id'], $a['type'], array('orderby' => $a['orderby'], 'order' => $a['order']) );

	$sep = $a['sep'];

	$output = '';

	foreach ( $terms as $term ) {
		$term_link = get_term_link( $term );
		$output .= '<a href="'.$term_link.'">'.$term->name.'</a>';
		$output .= $sep; 
	}

	return rtrim($output, $a['sep']);
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

After that, you can use this new shortcode in your template's "Fields and Text" block like this:


[get_terms_custom_order id="[wpv-post-id]" type="taxonomy-slug" orderby="parent" order="ASC" sep="<br>"]

Note: Please replace "taxonomy-slug" with the slug of your target taxonomy.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2375313
Screen Shot 2022-06-01 at 13.57.58.png
Screen Shot 2022-06-01 at 13.48.36.png
Screen Shot 2022-06-01 at 13.48.08.png

Hi Waqar!

Than you for the code. I think it's fair to say that I've done something wrong as I seem to have a shortcode on the front end. I've attached some screen grabs… Yikes!

#2375379

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

Can you please add new shortcode's name "get_terms_custom_order" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content and then check the page again?

In case the issue still persists, you're welcome to share temporary admin login details, along with the link to the page where you've added this shortcode.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

#2376315

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing the admin access.

The JetPack plugin's "Secure Sign On" feature is not allowing me to access the website's admin area.
( ref: hidden link )

Can you please disable this feature from the JetPack's settings, during the course of this investigation?

#2376335

Good afternoon Waqar,

I have just disabled the settings in Jetpack as requested.

Thank you

Lesley

#2376393

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for enabling the admin access.

For some reason, the code snippet for this custom shortcode was keep getting deactivated in the custom code section.

I've updated the second last line of the code from:


return rtrim($output, $a['sep']);

To:


return $output;

And it seems to be working now.
( screenshot: hidden link )

#2376413

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.