-
vidyutdev
I’ve got a setup with two CPTs on a travel site:
CPT 1: Tour Packages – which has a custom taxonomy called ‘Tour Location’ (terms like Austria, Rome, etc.)
CPT 2: Destinations – posts like Austria, Rome, Switzerland, etc.
Each Destination post is linked to its matching Tour Location via an ACF Taxonomy field.
Now, inside the Destination single template, I want to use GenerateBlocks’ Query Loop block to fetch and display the related Tour Packages (based on that ACF Taxonomy field).
How can I do it?
Thanks…
-
Hi there,
You can add a query block, add the taxonomies parameter, select Tour Location, and set the term to current post terms, set the post type to Tour packages.
Note that the Current post terms option is only available for GB Pro users.
-
vidyutdev
Ok, so will it fetch the ACF Taxonomy field selected Taxonomy posts?
Thanks
-
Yes, it should.
-
vidyutdev
Ok will try on a dev site.
Another question, can I dynamically fetch the archive link of that Category in my “Destination Posts”?
So I can put a link like “Show all the Tour Packages” of that Category.
Thanks
-
Yes, you can, use the term list dynamic tag, and select term for the link to field.
-
vidyutdev
Sorry for late, i tried creating that, i have 2 CPTs – 1) Tour Packages with taxonomy ‘Countries’; 2) Destination Details [here i added that ACF taxonomy meta field, which has that ‘Countries’ taxonomy.
Everything is working as you said, but the issue is;
In the – Countries Archive page created with GP elements, i’m also having that ‘Destination Details’ post.
So for example if there is a Post inside Destination Details CPT called ‘India‘ and i’m adding the term ‘India‘ from Countries taxonomy, then that Countries taxonomy term India archive including that ‘India’ post from the Destination Deatils CPT as well, which i don’t want…
So basically i wanna exclude that…
Thanks!
-
Did you manually set all the parameters for the Query block in the Archive Page element?
If so, try removing all the parameters enable the Inherit query from template option instead.
-
vidyutdev
Yes it is already ‘Inherit query from template’, i need to have that as i have dynamic facets.
Still i’m also getting posts from CPT of ‘Destination Details’ inside ‘Tour Packages’. As the same taxonomy is shared and linked, i just wanna exclude the destination details cpt posts here from that archive…
I tried exclude rule which is not working making the layout itself default gp layout.
-
Can I see the issue on your site? And point me to the CPT in question.
Let me know 🙂
-
vidyutdev
Issue: Excluding a CPT from a shared taxonomy archive
Hey everyone,
I’ve got two custom post types (CPTs) on my site:
Tour Packages – where I post different travel packages.
Destination Details – where I post information about each destination (e.g. Japan, Italy, etc.).
Both CPTs share the same taxonomy, called “Countries”.
What’s happening:
When I visit a Countries taxonomy archive page (for example, /countries/japan/), it currently shows posts from both CPTs — Tour Packages and Destination Details.
👉 Screenshot: https://i.postimg.cc/ryGsvnCf/Screenshot-2025-11-12-at-11-36-03-PM.pngWhat I want:
On the taxonomy archive pages (like the Japan archive), I only want to display Tour Packages, not the “Destination Details” posts.
Why this happens:
Each destination (like “Japan”) is also a post in the Destination Details CPT and uses the same “Countries” taxonomy term (Japan). So that “Japan” post from the Destination Details CPT is automatically appearing in the /countries/japan/ archive — but I don’t want it to.
In short:
Both CPTs share the Countries taxonomy.
I want to exclude posts from the Destination Details CPT on the taxonomy archive pages.
But I still want to show related Tour Packages inside the single Destination Details post (like showing Japan tours inside the Japan details page).
Question:
What’s the best way to exclude one CPT (Destination Details) from showing up on the shared taxonomy archive, while keeping it available for single pages and related queries?
-
What’s the best way to exclude one CPT (Destination Details) from showing up on the shared taxonomy archive, while keeping it available for single pages and related queries?
You need to use
pre_get_postsfilter to alter the output of the term archive. -
vidyutdev
How do we do that?
-
Alvind
Try adding this snippet:
function filter_countries_taxonomy_archive($query) { // Only modify the main query on the frontend if (!is_admin() && $query->is_main_query()) { // Check if we're on a Countries taxonomy archive page if ($query->is_tax('countries')) { // Set the post type to only show Tour Packages // Replace 'tour_packages' with your actual CPT slug $query->set('post_type', array('tour_packages')); } } } add_action('pre_get_posts', 'filter_countries_taxonomy_archive');Let me know if it works or not.
-
vidyutdev
I Alvind, it is giving me “No results found.”
-
What is your code, and did you replace
tour_packageswith the actual CPT slug?And are you using a block element – loop template? If so, is there any parameter added?
- You must be logged in to reply to this topic.