Forums › Forums › Search & Filter Pro › Parent/child taxonomy filtering
- This topic has 12 replies, 2 voices, and was last updated 8 years, 8 months ago by
Trevor.
-
Anonymous(Private) August 1, 2016 at 3:03 pm #52978
Hi,
I’m working on a filter to display a specific CPT which should be filtered on a custom taxonomy with ideally a parent / child relationship.
For example a course (CPT) suitable for adults (parent taxonomy) that want to learn coding (child taxonomy of adults)
When I setup the filter to display the taxonomy it shows the parent taxonomies including their children all in one list.
Is it possible to split this so you first have to select the parent taxonomy and based on that choice you can pick your child taxonomy? After that second choice you’ll see all the related courses.
The current setup can be found here: https://habitask.bijna.online/opleidingswijzer/
Thanks in advance,
NielsTrevor(Private) August 1, 2016 at 3:17 pm #52982Hi, this is a somewhat general reply, but here goes …
You should not have any taxonomy/meta field appear more than once in any one form. It is a common mistake users make. Instead you should have Custom Taxonomies and Custom (Meta) fields for your data. I make very few sites that genuinely are blogs, and so I switch off normal posts, categories and tags, and use only Custom Post Types, Custom Taxonomies and Custom (meta) fields. I also do not have hierarchical taxonomies. Each parent that you might want to do this with should be a separate taxonomy. They will automatically filter if you have Auto Count ‘on’ and hide empty values ‘on’ for each form field.
The latter gives you a much cleaner ‘conditionality’ to select fields. As the the original question, let me know how you get on?
I generally use the CPT UI and ACF plugins to add this functionality.
Anonymous(Private) August 2, 2016 at 9:50 am #53082Hi Trevor,
Thanks for your general reply. I guess that’s the way to go to create a custom taxonomy for every parent taxonomy. But is there a way to setup some parent-child relation regarding these custom taxonomies with Search&Filter?
You can do so with WP Types or other related plugins but that’s on a CPT level and not a taxonomy afaik.
Also, really not related to this question but can you only show results after a filter has been applied?
Thanks,
NielsTrevor(Private) August 2, 2016 at 10:03 am #53084Hi Niels
Our plugin will filter by reason of which values are entered in the post editor. In effect, the post itself becomes the link between the parent and child. As soon as you select a parent, only the children that are used in the posts with that parent are visible.
There is no need for a plugin like Types in a correctly structured site.
As to the second question, if I understand you correctly, S&F Pro has a function (
is_filtered
) where you can test if any filter has yet been applied, and thus you can restrict the showing of ANY results until a filter has been applied.Search for that function in the forum, for example, this is the most recent thread:
https://support.searchandfilter.com/forums/topic/shortcode-results-dont-display-results-until-click/
Anonymous(Private) August 2, 2016 at 11:05 am #53092Hi Trevor,
Thanks for the
is_filtered
function, got that part sorted now.But back to the taxonomy / parent-child question. I have one CPT now (Courses) and two taxonomies (Department and Job).
Each Course is suitable for a certain department and job. In the backend each course has a department and job checkbox to setup the correct taxonomy.
On the front-end I have two drop downs (department and job) to filter the courses. This works fine but shows all jobs when there’s a department selected. However I only want to show the jobs that are available to filter based on the first selection (department).
So basicly filter all courses by department first, after that you should only see jobs in the dropdown that are related to courses which are in range of the first selector (department).
Can that be done with only using two taxonomies?
Anonymous(Private) August 2, 2016 at 12:13 pm #53100Thanks for taking a look and making some changes Trevor, it seems to be working as I want it to do so that’s awesome!
But what have you changed? I noticed that it hides empty terms no and show a counter. But I guess that you’ve changed something else as well?
-
AuthorPosts