Skip Navigation

[Resolved] Taxonomy View showing terms applied to related posts

This thread is resolved. Here is a description of the problem and solution.

Problem: I have two custom post types - Characters and Photographs - linked in a post relationship. The Photographs CPT has a custom taxonomy Photoshoots, with terms for each Photoshoot assigned to each Photograph. In the template for Characters posts, I would like to display a list of all Photoshoots terms applied to all Photographs posts related to the current Character post.

Solution: The problem does not have a straightforward solution, because you need to filter a View of taxonomy terms by the properties of a related post type. The best solution requires you to use the legacy Views editor to create a nested View structure that produces the desired terms list.
See step-by-step instructions in the following comment: https://toolset.com/forums/topic/taxonomy-view-6/#post-2101763

This support ticket is created 3 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 22 replies, has 2 voices.

Last updated by Christian Cox 3 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#2103973

So how do I learn what these views are doing beyond calling this witchcraft?!?! I don't want to just KNOW it worked, I want to UNDERSTAND... View 1? I get. View 3 I almost can wrap my head around. View 2? Witchcraft?!!

The Content Template thing we just did? Ancient Magic??!?!?

#2104037

Ok awesome!
The Content Template thing we just did?
Content Templates are like Toolset's version of Oxygen templates. You can design a template and apply it to a single post or an entire post type, and the template will override whatever you place in the posts contents. Or, you can put arbitrary content in a Content Template and insert that Content Template in a post or another template somewhere. That template will be rendered in place. That is what we are doing here to get around the problem where nested shortcodes inside shortcode attributes are not supported by the Oxygen template elements. Toolset's Content Templates support nested shortcodes inside other shortcode attributes.

View 3 I almost can wrap my head around.
The View is configured to show the Photoshoot taxonomy, and the Query Filter filters by term ID, using the shortcode attribute 'terms' to supply that list of term IDs. The shortcode attribute 'terms' is used to provide the list of term IDs in a dynamic way. We could just as easily use a hard-coded list of IDs like this:

[wpv-view name="view-3" terms="1,2,3,1,,3,2,2,1,3,1"]

That would give you a formatted list of term ID 1, term ID 2, and term ID 3, but it would drop any duplicates in the list of IDs. In summary, View 3 just says "give me a list of term IDs in a shortcode attribute called 'terms' and I will produce a formatted, sorted list of terms, without duplicates, for you." We use this because the other two Views produce a list of term IDs that include some duplicate IDs in an unsorted, unformatted way. We need to sort them reasonably and format a list of term names, which is what this View does.

View 1? I get.
Right, this effectively produces a list of related Photograph posts for the current Character post:
Photograph A,Photograph B,Photograph C
But we do not output the Photograph titles, we loop over those and for each Photograph post we insert the results of View 2. So each time View 2 is executed, it is executed in the context of a different Photograph post (why View 2 Query Filter is set to the "current post", which is the current Photograph post in the loop of View 1).

View 2? Witchcraft?!!
View 2 is executed once for each related Photograph post (in the loop of View 1). We do this because we want to get a list of all the terms assigned to each related Photograph post. So if you think about this in the context of View 1, altogether we get something like this nested loop structure:
Photograph A (this is not output anywhere),
-- Term 1 (we output the term ID),
-- Term 2 (we output the term ID),
Photograph B (this is not output anywhere),
-- Term 3 (we output the term ID),
Photograph C (this is not output anywhere),
-- Term 1 (we output the term ID),
-- Term 2 (we output the term ID),
-- Term 3 (we output the term ID),
This is why there can be duplicates in the list of term IDs, why there are some empty commas, and why they are not in any logical sort order. because Photograph A and Photograph C might have the same term assigned. So Views 1 and 2 together produce a list of term IDs, something like:
,1,2,,3,,1,2,3,
Then we feed that list of term IDs into View 3 using a shortcode attribute, and get the final output something like:
Term 1, Term 2, Term 3

#2104105

I read everything you wrote but my brain broke in the middle. I'm going to be reading this a few times.

I really wish I was able to sit down over Zoom and ask questions.
My brain wants to work like this: hidden link

This is a setup I did: hidden link

#2104119

An elegant way to look at the data structures and relationships involved. Let me know if there's something specific that you need more information about, or doesn't make sense. I can try to explain further.

#2104489

I'm really curious as to how I would insert a photo or character into a regular blog post?

#2104863

Could I create a shorthand Content Template in Toolset for a Character or Photograph (or any CPT) and lay it out in Blocks... build it like it's own presentable version of that CPT. Then insert THOSE in my Blog posts?

#2105581

My issue is resolved now. Thank you!

#2111419

I'm really curious as to how I would insert a photo or character into a regular blog post?...Could I create a shorthand Content Template in Toolset for a Character or Photograph (or any CPT) and lay it out in Blocks... build it like it's own presentable version of that CPT. Then insert THOSE in my Blog posts?
Hello, sorry but this ticket was closed out before I got a chance to see your question. Yes, you could build a Content Template to display a single Character or Photograph in Blocks, and insert that Content Template using the wpv-post-body shortcode in the contents of a Blog post, or in an Oxygen template applied to Blog posts, or in a Toolset Content Template applied to Blog posts (depending on which templating system you plan to use for Blog posts).

Use the "item" attribute in the wpv-post-body shortcode to specify which post you want to display in the Content Template, by post ID. So if you want to include Character ABC (assume this is post ID #123) in some Blog post, you would first create a new Content Template in the Block Editor and do not assign it to any content. Design the template in the Block editor however you would like, using the "View with" menu at the top to select any post to use as the post source. Insert this Content Template in the desired Blog post's contents, or in some template applied to that Blog post, using the wpv-post-body shortcode with the item attribute, hard-coded to the post ID of the Character ABC post:

[wpv-post-body view_template="your-new-content-template-slug" item="123"]

The item attribute can be used to display any arbitrary post by ID.

If you have questions about that feel free to open a separate ticket and we can discuss in more detail.