Skip Navigation

[Resolved] displaying a taxonomy

This support ticket is created 2 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 – 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 5 replies, has 2 voices.

Last updated by Steve 2 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2283015

This is for a museum that has shows in different galleries I have a view that displays a synopsis of each show on a page like this (below) The gallery name is a taxonomy wpvgallery

[wpv-view name="name of view" wpvgallery="firstgalleryname" ]
[wpv-view name="name of view" wpvgallery="secondgalleryname" ]
[wpv-view name="name of view" wpvgallery="thirdgalleryname" ]

Occasionally a single show is in multiple galleries and when that's the case both gallery names appear within both of the view when i insert the taxonomy in the loop to display the gallery's name

You can see the issue here
hidden link

The Horse show is in two galleries and it displays twice (which is acceptable as its in two rooms) but it would be better if only the correct and single gallery name appeared in each of the respective views.

I know i could simply remove one of the short codes but i'd like to keep the museum staff off that page- so am looking for something a bit more programmatic

Thanks

#2283397

Waqar
Supporter

Languages: English (English )

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

Hi,

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

If I understand correctly, you'd like each gallery (e.g. "The Founder's Gallery, Griffin Main Gallery") to show only once on the page, even if it is covered in the results of multiple views. If that is correct, I'll need to see how these views are set up in the admin area.

Can you please share temporary admin login details, in reply to this message?

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

regards,
Waqar

#2285829

Waqar
Supporter

Languages: English (English )

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

Thank you for sharing the admin access.

I was able to hide the duplicate results, using the following steps:

1. In the view "GriffinGalleriesBlockView", I included the "data-post-id" attribute in the div with class "main-gallery-show":
( screenshot: hidden link )


<div class="main-gallery-show" data-post-id="main-gallery-show-[wpv-post-id]">

2. Next, in the view's "JS editor", I included some custom script that hides all div elements with class "main-gallery-show", where the "data-post-id" attribute matches and it is not the first instance:
( screenshot: hidden link )


jQuery( document ).ready(function() {
	jQuery('.main-galleries-wrap .main-gallery-show').each(function(index, value) {
		var dataID = jQuery(this).attr('data-post-id');
		jQuery("div[data-post-id="+dataID+"]:not(:first)").hide();
	});
});

This way, all the repeated results are hidden.

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#2286003
griffin-shows.jpg

Waquar- Im sorry we're not understanding each other fully- what you did removes the whole second instance of the show- Im wanting to remove the additional show names. The attached image has crossed out the info id like not to display

So the
[view that selects the griffin main gallery] shows two titles "Griffin Main Gallery and the Founders gallery - But in that view id like it to on show the Griffin Main Gallery taxonomy title ony

in the [view that selects The Founders Gallery] Id like it to display that galleries name only and not the Griffin Main Gallery

Is that clearer? Sorry

#2286831

Waqar
Supporter

Languages: English (English )

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

Thanks for writing back and I apologize for the confusion earlier.

The slug of the target gallery term passed through the shortcode attribute 'wpvgallery' can be accessed in the view using the "wpv-attribute" shortcode:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-attribute


[wpv-attribute name='wpvgallery']

However, you need to show this term's name and not the slug. For this, you'll need to register a custom shortcode, that accept the term's slug value and returns its name:


add_shortcode( 'get_term_name_custom', 'get_term_name_custom_func');
function get_term_name_custom_func($atts){
	$slug = $atts['slug'];
	$taxonomy = $atts['taxonomy'];

	if ( (!empty($slug)) && (!empty($taxonomy)) ) {
		$category = get_term_by('slug', $slug, $taxonomy, 'ARRAY_A');
		if($category) {
			return $category['name'];
		}
	}
}

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 place of the 'wpv-post-taxonomy' in the view, like this:


[get_term_name_custom slug='[wpv-attribute name='wpvgallery']' taxonomy='gallery']

This way, each result will show only the name of only the filtered gallery term and not all the attached terms.

#2286915

Thanks so much that solved my issue perfectly

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