I am trying to: Configure a view that (a) displays all "Practice Areas" CPT parent posts in a single select filter, and (b) returns the child posts of the selected parent.
I visited this URL: Edit View > Filter Editor > New Filter > Post Relationship
I expected to see: Option to add "Practice Areas" CPT post parents as filter
Instead, I got: "Before using a post relationship filter, you need to set a Types parent-child relationship for the post types selected in the Content Selection section."
The parent-child relationship documentation (https://toolset.com/documentation/user-guides/creating-post-type-relationships/) seems to only address situations where the Parent CPT and Child CPT are different CPTS.
In our case, the parent and child are the same CPT ("Practice Areas" - see attached screenshot) .. and we can not find any references for how to create a parent filter that returns children of the same post type.
Specifics:
We are working with an existing custom post type called "Practice Areas". There are 150 Practice Area custom posts in the WP database. These custom posts are organized hierarchically into 15 top level Practice Areas with approximately 10 child Practice Areas each.
The resulting structure is as follows:
Top Level Practice Area 1
- Child Practice Area 1
- Child Practice Area 2
..
- Child Practice Area x
...
Top Level Practice Area N
- Child Practice Area 1
- Child Practice Area 2
..
- Child Practice Area z
...
In other words, some Practice Areas are parents with children that are also Practice Areas.
We want to build a view where (a) the parent practice areas are all displayed in a single select filter, and (b) the child practice areas of the selected parent are returned by the view.
How can we accomplish this?
Thanks!
1. In our case, the parent and child are the same CPT
This is impossible.
I think you mean the WordPress page hierarchy, which you can also enable for CPT's created with Types.
2. For this kind of relationship you cannot create a Custom Filter.
You can thou add it as a Query Filter, but this is not a Front End Filter.
3. I will ask the Developers why we did not include this as a Custom Filter as well, I think it would make sense to do so.
Thank you Beda.
<quote>1. In our case, the parent and child are the same CPT
This is impossible. I think you mean the WordPress page hierarchy, which you can also enable for CPT's created with Types.</quote>
Yes you are correct I was indeed referring to the WordPress page hierarchy.
As a work around I decided to add a new taxonomy to the CPT and use the taxonomy to filter the CPT. The filtering now works as desired; but now I'm having problems setting a default term for the taxonomy filter.
It appears that Views allows you to add a "default" filter option to wpv-control-post-taxonomy but it apparently defaults to select "All" and can not be set to a particular term in the taxonomy.
Since I took a new approach I opened this ticket to request assistance:
https://toolset.com/forums/topic/help-with-setting-taxonomy-filter-default-to-a-particular-term-in-taxonomy/.
Can you take a look at that ticket? Or do you want to address it in this ticket?
Thanks Beda
I will take a look there and keep this here as a reference to the new feature for the Filter I mentioned above.
Thank you for your exceptional understanding and patience.