[Resolved] get slug of parent taxonomy

This thread is resolved. Here is a description of the problem and solution.

Problem:

Display parent term's information in sub-term archive page.

Solution:

There isn't such kind of built-in feature within Toolset, it needs custom codes, for example:

https://toolset.com/forums/topic/get-slug-of-parent-taxonomy/#post-1489745

Relevant Documentation:

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 2 voices.

Last updated by Ido Angel 4 months, 4 weeks ago.

Assigned support staff: Luo Yang.

Author
Posts
#1489493

hey,
i have taxonomy called "free tags", with the slug "free-tags".
under this, i have many terms. let say, for example's sake: "wisdom", "ignorance", "stupidity".
archive pages have this URL:
hidden link
hidden link
hidden link

how would i display the parent taxonomy slug (e.g in this case: "free-tags") in the term's archive page? what's the right shortcode?

I need this because I want to create a link within the archive page to a search view. something like:

<a href="<em><u>hidden link</u></em> info='slug']&wpv_filter_submit=SUBMIT&wpv_sort_orderby=post_title&wpv_sort_order=asc">

thx!!

#1489731

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (įŽ€äŊ“中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hello,

There isn't such kind of built-in feature within Toolset, it needs custom codes, for example:
1) Add below codes into your theme file functions.php:

add_shortcode('parent_term_info', function($atts, $content){
	$atts = shortcode_atts( array(
		'tax' => '',
		'output' => 'slug'
	), $atts );
	$res = '';
	$termObj = get_queried_object();
	if(isset($termObj->parent) && !empty($atts['tax'])){
		$parent_term = get_term( $termObj->parent, $atts['tax'], ARRAY_A);
		if(isset($parent_term[$atts['output']])){
			$res = $parent_term[$atts['output']];
		}
	}
	return $res;
});

2) Dashboard-> Toolset-> Front-end Content, in section "Third-party shortcode arguments", add above shortcode name: parent_term_info

3) Use the shortcode to setup the link, like this:

<a href="<em><u>hidden link</u></em> tax="category"]&wpv_filter_submit=SUBMIT&wpv_sort_orderby=post_title&wpv_sort_order=asc">[parent_term_info tax="category" output="name"]</a>

Please replace "category" with your custom taxonomy slug

#1489743

Hey Luo!
Thanks for the code 🙂
I need the "tax" to be the current archive's parent taxonomy (I'm placing the link in the archive view of ALL taxonomies).
Will that be possible?
Thanks!
Ido

#1489745

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (įŽ€äŊ“中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Yes, it is possible, you can change the PHP codes as below:

add_shortcode('parent_term_info', function($atts, $content){
	$atts = shortcode_atts( array(
		'output' => 'slug'
	), $atts );
	$res = '';
	$termObj = get_queried_object();
	if(isset($termObj->parent) && isset($termObj->taxonomy) ){
		$parent_term = get_term( $termObj->parent, $termObj->taxonomy, ARRAY_A);
		if(isset($parent_term[$atts['output']])){
			$res = $parent_term[$atts['output']];
		}
	}
	return $res;
});

And use above shortcode like this:
slug: [parent_term_info output="slug"]
name: [parent_term_info output="name"]

Don't forget step 2)
Dashboard-> Toolset-> Front-end Content, in section "Third-party shortcode arguments", add above shortcode name: parent_term_info

#1489747

Oh, and also - this link:

<em><u>hidden link</u></em>

opens the page and shows the view, but i'm getting all results and they are not filtered by the tag.

#1489755

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (įŽ€äŊ“中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Please test as I mentioned above:
slug: [parent_term_info output="slug"]
name: [parent_term_info output="name"]

Make sure they output correct results.

If they do output courrect results, you will need setup the link manually according to your website settings.

If you need more assistance for it please provide a copy of your website, also point out the problem page URL and view URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1489839

thx, but the archive page comesout blank with the code in it:

<a href="<em><u>hidden link</u></em> output='slug']=[wpv-taxonomy-archive info='slug']&wpv_filter_submit=%D7%97%D7%99%D7%A4%D7%95%D7%A9&wpv_sort_orderby=post_title&wpv_sort_order=asc">ה×Ļגה ×ĸל גבי מפה</a>

but I mananged to get this done by using jQuery:

  $(".maptag").click(function() {
    var url = $(location).attr('href').split('/');
    var taxslug = url[url.length-2];
    var archiveslug = url[url.length-3]
    window.location.href = "<em><u>hidden link</u></em>"+archiveslug+"%5B%5D="+taxslug+"&wpv_filter_submit=%D7%97%D7%99%D7%A4%D7%95%D7%A9&&wpv_filter_submit=%D7%97%D7%99%D7%A4%D7%95%D7%A9&wpv_sort_orderby=post_title&wpv_sort_order=asc";
    return false;
  });