admin管理员组

文章数量:1122846

I'm building a WordPress site using Elementor Pro and Advanced Custom Fields (ACF). I have two custom post types: Countries (for country pages) and Sights (for different sights/landmarks in each country). I’ve also created a custom taxonomy called "Countries" that’s assigned to both the Countries post type and the Sights post type.

Each Country post has an associated country term (e.g., "Moldova," "Estonia"), and each Sight post is tagged with the country it belongs to using the same taxonomy. I want to display a list of Sights on each Country page, but only those that match the current country.

The URL structure is like this: /countries/moldova/ (for Moldova's page), and I want to display only the Sights that belong to Moldova on the Moldova page, and similarly, Estonia sights on the Estonia page.

What I’ve tried so far is using the Elementor Pro Post Widget and filtering by taxonomy terms, but this requires me to manually set the term, which defeats the purpose of a dynamic template. I’ve also tried using FacetWP to filter the Sights, but I still can’t figure out how to make the filter dynamically pull the country from the URL and match it with the taxonomy term of the Sights.

How can I dynamically filter Sights by country on each Country page based on the URL, using Elementor Pro (or FacetWP), without manually setting the term for each page? I want the template to work for any country page and automatically display the corresponding Sights. Is there a way to achieve this dynamically, preferably without custom coding, or do I need a code snippet?

本文标签: How to Dynamically Filter Custom Post Types by Taxonomy Based on URL in Elementor Pro and ACF