Skip Navigation

[Resolved] Check the current taxonomy Single name and display the correct Taxonomy View

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 6 replies, has 3 voices.

Last updated by umbertoZ 1 year, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2510877

Hi Luo, the solution works fine, the only issue I still have is that I'm using the same archive for different taxonomies, so I've to create a different Taxonomy View for each one of them.

There are 6 taxonomies, I would like to not load 6 views at the same time in the archive, to prevent 6 calls to the database, even if 5 of them will return an empty result.

So I thought to use a conditional to check the current taxonomy Single name and display the correct Taxonomy View. I tried with [wpv-taxonomy-archive info="taxonomy"], but the output is empty.

Any suggestion?

I know I could create a different archive for each taxonomy. But i would prefer to work with only one archive.

cheers

#2510915

Hello,

The shortcode [wpv-taxonomy-archive] works only in view's loop, in your case, it needs a custom codes, I have setup a demo in your website:
1) Edit the custom codes snippet "custom1", create a new custom shortcode [wpv_is_tax]
hidden link
line 123~132:

add_shortcode('wpv_is_tax', function($atts, $content) {
	global $wp_query;
	if(isset($wp_query->query['wpv_fake_archive_loop'])){
      	$archive_loop = $wp_query->query['wpv_fake_archive_loop'];
      	if($archive_loop['type'] == 'taxonomy' && $archive_loop['name'] == $atts['tax']){
          	$res = do_shortcode($content);
        }
	}
  	return $res;
});

2) Edit the WordPress Archive:
hidden link
section "Output Editor", line 21, use above custom shortcode like this:

[wpv-is-tax tax="destination"] Here display different post view's shortcode for <strong>destination</strong> taxonomy archive pages [/wpv-is-tax]

More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-taxonomy-archive

#2511015

Hi Luo, thanks for the solution.
I tested it on hidden link, but I don't see the expected output "Here display different post view's shortcode for destination taxonomy archive pages".

I understand the code, but I don't understand "wpv_fake_archive_loop". Can you explain the use of this name?

Maybe I will use your example to build another shortcode with a switch to check all the possible cases and output directly the View I need.  

cheers

#2511455

I have checked the custom PHP codes as below:

add_shortcode('wpv-is-tax', function($atts, $content) {
	global $wp_query;
  	$res = '';
  	if(is_tax($atts['tax'])){
    	$res = do_shortcode($content);
    }
	if(isset($wp_query->query['wpv_fake_archive_loop'])){
      	$archive_loop = $wp_query->query['wpv_fake_archive_loop'];
      	if($archive_loop['type'] == 'taxonomy' && $archive_loop['name'] == $atts['tax']){
          	$res = do_shortcode($content);
        }
	}
  	return $res;
});

Please test again, check if it is fixed.

The variable "wpv_fake_archive_loop" works when you pass URL parameters to WordPress Archives

#2512285

Hi Luo, the custom shortcode worked perfectly!!!

I still have a similar issue in the same website, I suppose you will split this too.

I've the Local Ads custom post type. Each post has only one multi line custom field where we store an affiliate program script.
We assigned all the taxonomies we have (Region, Area, Towns, etc.) to Local Ads and to Sights CPTs. Local Ads has only one term assigned to one of the taxonomies, while Sights has different terms (for example, a Region, an Area, a Town).

I've built a view to display Local Ads, filtered by taxonomies, on the Sights single content template.
I've selected Local Ads post-type and I've added a query filter for each taxonomy by "page where this View is shown" and logic OR.

What I expect is to display 1 or more Local Ads on each Sight post, but what I get is a loop of Sights.

This is the view:
/wp-admin/admin.php?page=views-editor&view_id=12559

This is the Sights single template:
/wp-admin/post.php?post=225&action=edit

These are a couple of Sights examples (see at the bottom of the page):

/sight/slievemore/

/sight/newport/

cheers

New threads created by Waqar and linked to this one are listed below:

https://toolset.com/forums/topic/split-view-with-multiple-taxonomies-filter/

#2514409

Hi,

Glad that Luo's code suggestion helped.

I've created a separate ticket for your recent question and will follow up on it shortly.
( ref: https://toolset.com/forums/topic/split-view-with-multiple-taxonomies-filter/ )

You're welcome to mark this ticket as resolved and start a new one for each new question or concern.

regards,
Waqar

#2514577

My issue is resolved now. Thank you!