I'm working on two related post types: resource, and resource list. They have a many-to-many relationship, where each list includes a group of resources and a resource could be reused on multiple lists. A resource could have a different description on each list where it shows up, and I've got an intermediary post type that provides the description as well as a numerical field used to order the resources within the list. I've got a view based on the intermediary post type that shows each resource with a title and URL from the resource post type, plus the description from the intermediary post type, in the order set by the intermediary post type numerical field. So far, so good.
The part I haven't figured out yet is that some of the lists have subcategories within them - for instance, hidden link and hidden link. There are other lists (like hidden link) that don't have subcategories and shouldn't display any extra headings. I'm basically trying to figure out how to replicate this content using Toolset.
I started out trying to follow the instructions on https://toolset.com/2015/07/how-to-group-posts-by-category/, but ran into a snag because my view is based on the intermediary post type, which doesn't allow taxonomies or have taxonomy as a query filter option. What else could I try?
Hello,
Please elaborate the question with more details:
How do you setup the post types and taxonomies?
Where do you want to display the view? in the single single "resource list" post or single "resource" post?
I need to test it in my localhost, thanks
Hi! I would like to display the view on the resource list (called "Discover It Online list") post. See the attached toolset-resource-list.png screenshot for what I've got so far, without the category headings within the page. I want to get that page set up like hidden link.
I'm also attaching screenshots showing the new resource and Discover It Online list screens, plus the connection screen. Let me know what other details you need to look into this.
Thanks!
I assume we are talking about the custom taxonomy "Resource categories" in your screenshot:
hidden link
And you are using below structures:
1) Two post types: "resource" and "resource list", with many-to-many relationship using below intermediate post type
2) there is a custom numeric field "order" in the intermediate post type
3) the custom taxonomy "Resource categories" is registered to post type "resource"
And you are going to do this:
In a single "resource list" post, setup a post view:
- query posts of intermediate post type
- display related "resource" posts:
- order the results by numeric field "order"
- groups the results by taxonomy "Resource categories"
If it is, it is expected result:
my view is based on the intermediary post type, which doesn't allow taxonomies or have taxonomy as a query filter option.
You might consider this:
1) Move the numeric field "order" to post type "resource"
2) in a single "resource list" post, setup a nested view:
a) Parent taxonomy view:
- query terms of taxonomy "Resource categories"
- in view's loop, display below child post view
b) Child post view:
- query "resource" posts
- filter by:
b1) post type relationship between "resource" and "resource list"
b2) Resource categories set by the parent Taxonomy View
- in view's loop, display "resource" post information
Hi Luo - thanks for the reply, but if I understand right, I don't think this would quite accomplish what I'm trying to do. The reason I'm using an intermediate post type is that on different lists, the same resource could have 1) a different order and 2) a different description. Moving those fields to the resource post type would take away that ability, unless I'm missing something (which is very possible!). Any other ideas? I've thought about doing something like adding a new post type for "parent list" and pulling in multiple child lists instead of using a taxonomy, although I haven't figured out exactly how that would work either... I'm open to different ways of doing this and only set out to use a taxonomy because that's what that help article had suggested doing.
Thanks again--
I don't think you are missing something, and you are correct, if you are querying posts of intermediary post type, you can filter/order by custom fields/taxonomies of intermediary post type, it is a limitation of WordPress WP_Query:
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
I have already provide my suggestion above:
https://toolset.com/forums/topic/grouping-posts-in-a-view-with-an-intermediary-post-type/#post-1244948
in your case, you need to consider:
Move the numeric field "order" to post type "resource", so you will be able to order/filter the results by taxonoies/fields of post type "resource".
OK, I think I'm getting it! So now I have the nested views set up to group the resources by category. A follow-up question: currently all of the taxonomy terms display on all of the list pages, even if there are no resources associated with that term for a given list - see attached. Is there a way to set a condition where the parent view only displays the taxonomy term if there are associated resources on that specific list? This is what I currently have in the loop editor for the parent taxonomy view:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<h2>[wpv-taxonomy-title]</h2>
[wpv-view name="online-resource-take-2"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
You can try to move the taxonomy title into child post view "online-resource-take-2", for example, edit the codes you mentioned above, from:
...
<h2>[wpv-taxonomy-title]</h2>
[wpv-view name="online-resource-take-2"]
...
To:
...
[wpv-view name="online-resource-take-2" term_title="[wpv-taxonomy-title]"]
...
Edit the child post view "online-resource-take-2", in section "Loop Editor", display term's title, like this:
...
[wpv-items-found]
[wpv-attribute name="term_title"]
....
[/wpv-items-found]
...
More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute
This shortcode displays the value of an attribute in a View shortcode.
OK, great - that worked! One more follow-up question: for some lists, there won't be any subcategories (ie none of the taxonomy terms used), and for those lists, I would ideally like to fall back to a different view instead. Right now I've got:
[wpv-layout-start]
[wpv-items-found]
<h2>[wpv-attribute name="term_title"]</h2>
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-post-body view_template="loop-item-in-online-resource-take-2"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpv-view name="online-resource-description-for-list"]
[/wpv-no-items-found]
[wpv-layout-end]
This is close, except that the online-resource-description-for-list view repeats once for each taxonomy term from the parent view. Is there a different way to accomplish this without the repetition?
My issue is resolved now. Thank you!