Skip Navigation

[Resolved] Outputting Taxonomy name of parent taxonomy view loop item inside the child view

This support ticket is created 4 years, 2 months 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by timC-5 4 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#2211653

Tell us what you are trying to do?
I'm using a parent taxonomy view and I'm trying to output the taxonomy name inside the child view outside of the loop of the view as a heading. This means the heading will only be displayed when the taxonomy is populated with items from within the child view rather than if the taxonomy is populated regardless.

This is because we have 2 taxonomies affecting the child view which can cause the parent to appear empty.

When adding the "[wpv-post-taxonomy]" field, there isn't a post selection for "set by parent taxonomy view" like there is in the filters which would handle it perfectly, do you know if this is possible to do with a custom function?

Is there any documentation that you are following?
Not anything I could find, although I didn't look very heavily.

What is the link to your site?
hidden link
The user and password for the htaccess is sws.
The view in question is under the Results tab.

#2211871

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tim,

Assuming that you've already had the view setup and it is displaying correctly, you only need to check if the term has a child correct and display the parent title if it does.

In such a case a custom function might be helpful here. Please try this below.

// Add Shortcode
function check_if_child_terms_empty( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'term_id' => '',
			'taxonomy_name' => '',
		),
		$atts
	);

	$child_terms_arr = get_term_children($atts['term_id'],$atts['taxonomy_name']);
	if(empty($child_terms_arr)){
	    return true;
	}

}
add_shortcode( 'check_if_child_terms_empty', 'check_if_child_terms_empty' );

The code above will return true if the taxonomy doesn't have any child terms. To use it you will format the shortcode like this [check_if_child_terms_empty term_id='[wpv-taxonomy-id]' taxonomy_name='[wpv-taxonomy-title]']

Furthering this you can use the shortcode above in our conditional statement to check if the function returns true. Here is an example below.

[wpv-conditional if="('[check_if_child_terms_empty term_id='[wpv-taxonomy-id]' taxonomy_name='[wpv-taxonomy-title]']' ne '1' "]

Display Taxonomy Title

[/wpv-conditional]

However before you can use the custom shortcode in our conditionals you must first add the shortcode to Toolset -> Settings-> Custom Code and activate it.

Then go to Toolset->Settings->Frontend and under 3rd party shortcode arguments add the name of the shortcode.

Please let me know if this helps.
Thanks,
Shane

#2211911

Hi Shane,

My apologies, I failed to mention the child view is outputting a post type (Results) not child terms. What I need is to check if the Child View has Posts (Results) related to the Taxonomy in the loop of the Parent Taxonomy View after Child View filters have been applied and if so output the title otherwise don't output the title.

I can provide a login if needed.

#2211953

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tim,

This a bit more tricky to achieve given that we are going to need to check if the taxonomy has any posts.

Yes please provide the admin access to the site so that I can have a look.

Thanks,
Shane

#2212931

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tim,

Thank you for your patience, this should now be working.

I used the shortcode below to evaluate your view to see what the results are then pass it to the conditional statement in views to hide/show the items.

function check_view_result() {
$args = array(
    'title' => 'Results output for Concert view'
);
$view = render_view( $args );
if(strlen($view) == 62){
return 'the view is empty';
}

}
add_shortcode( 'check_view_result', 'check_view_result' );

Please let me know if this helps.
Thanks,
Shane

#2212935

My issue is resolved now. Thank you!

Absolutely phenomenal support, thank you very much Shane.