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
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
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
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
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
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
My issue is resolved now. Thank you!