Skip Navigation

[Resolved] Help with a View showing multiple levels of hierarchy

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

Problem: I have several post types arranged in a combination of one-to-many and many-to-many Views. I would like some assistance creating a View filtered by Clients, and showing information about Tracks, Aliases, Pitches, Writers and Writer Shares.

Solution: Create a View of Pitches, filtered by parent Clients. In the View of Pitches, use a Content Template to access the parent Alias, where you can access the grandparent Track. Use the id attribute as needed to access custom field values or post information. Use a View of Writer Shares, filtered by parent Track, set by a shortcode attribute. In the Loop Output of that View, you can include information about the Writer Share and its parent Writer post. You can place this View in your Content Template to access the grandparent Track ID, and pass that into the View's shortcode attribute filter.

Relevant Documentation:
More information about post relationship filters:
https://toolset.com/documentation/user-guides/displaying-related-child-posts/

More information about displaying fields from grandparent posts:
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

This support ticket is created 6 years, 9 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.

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)

This topic contains 13 replies, has 2 voices.

Last updated by ScottM9386 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#619758

Hi,

I really try to figure stuff out but I just can't get how to set up this view, after many, many hours.
CPT's: (Terminology: "Tracks" are music tracks, "Aliases" are alternate titles for the track "Pitches" are submissions to "Clients" (production houses))

Tracks (parent)
|
Aliases (child of Tracks and Parent to "pitches" below)
|
Pitches (Child of Aliases and intermediary between Aliases and Clients)
|
Clients

The view I want:
FILTER BY CLIENTS and show:
Track title | Alias titles | Pitch fields | Client title

All linked together by their relationship.

Track "ABC" has several Aliases and those Aliases have Pitch FIELDS attached to them and connected to a Client

I figured out how to show "Track - Alias - Pitch - Client" together but not how to add a "FILTER BY CLIENT"

To show "Track - Alias - Pitch - Client" I created a View using pitches as content with
Query = "Select posts that are a children of the current post in the loop." and used [wpv-post-title id="$client"] to get Client.
Then I nested this View in a View with content "Alias" and using [wpv-post-title id="$track"]
But I need to add a "FILTER BY CLIENT" to this, but this option doesn't seem to be available.

Maybe it needs to be approached from a different angle?
Thank you!

#619800

Okay if I understand your setup correctly, it sounds like "Pitch" is a child of "Alias" and also a child of "Client". In other words "Clients" and "Aliases" are in a many-to-many relationship with an intermediary post type of "Pitches". So to filter a View of Pitches by Client, you must use a "Post Relationship" filter.
- Create a new View of Pitches
- If you are not able to see the "Filter Editor" panel, scroll up to the top right corner of the admin screen and click "Screen Options". Activate the Filter Editor panel here
- Place your cursor in the Filter Editor panel and insert a Post Relationship filter. Select the relationship "Clients > Pitches". This will create the filter control to filter by Client
- In the Loop Output editor, you can access the parent Client and Alias posts using the same id operator approach you mentioned before:

[wpv-post-title id="$client"] 
[wpv-post-title id="$alias"] 

- See below to access information from the grandparent Track post
- Insert this View in a custom Page

More information about post relationship filters:
https://toolset.com/documentation/user-guides/displaying-related-child-posts/

More information about displaying fields from grandparent posts:
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

Let me know if I have misunderstood your request.

#619808

Hi Christian,

Thank you for your reply.
Yes, I know how to do that.

What I'm looking for is to be able to include fields from "Tracks" as well. "Tracks" is a parent of "Aliases" and "Aliases" and "Clients" are parents of "Pitches" (as you understand).
Tracks have many Aliases and those Aliases have many Clients.
The View I'm looking for is:

FILTER BY CLIENTS and show:
Track title+Track fields | Alias titles | Pitch fields | Client title
With all relationships maintained - the "Track-Aliases" relationship - and those "Aliases" with their Clients (including the fields from Pitches)

I think it's a bit complex, multiple nested views?

Thank you!

#619820

What I'm looking for is to be able to include fields from "Tracks" as well.
Yes I think I understand you here. Let me explain further. Tracks are grandparent posts of Pitches, because Track is a parent of Alias, and Alias is a parent of Pitches. So the relationship is grandparent > parent > child, or Track > Alias > Pitch. The View you described is a View of Pitches, and you want to display information from the grandparent Track. The link I provided earlier describes how to access custom fields of a grandparent post:
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

The general idea is that you use another Content Template(s) to modify the post context, giving you access to the fields from a related post at any level of hierarchy. The Content Template will look something like this:

Title: [wpv-post-title id="$track"]<br />
Custom field: [types field="custom-field-slug" id="$track"]<br />

Replace "custom-field-slug" with the slug of the custom field on the Track post. If your custom post type slug is not "track", then change "$track" to match your new slug, preceded by a "$" symbol.

Then you will insert this new Content Template in your existing View of Pitches like this:

[wpv-post-body id="$alias" view_template="alias-track"]
#620674

Thank you Christian!
That worked great - after I wrapped my head around it 🙂
One more thing if I may, and I wish I added this to my original question.
There's yet other relationship info I want to add to this view:

Track (parent) Writers Share (child) Writer (Parent) - Many2Many. A "track" can have many "writers"

Is it possible to add this info as well to the above view? So the final view would look something like this: (I'm just missing he final part of this equation - the writer info)

SORT BY CLIENT
Track Title | Alias Title | Pitch Fields | Client | Writer Share Fields | Writers

Thank you!!!

#620736

You need a few more steps to access Writer Share and Writer information from a View of Pitches:
- To show fields from the Writer Share post, create a View of Writer Shares, filtered by post relationship. For now, select a specific parent Track. We can work on making it dynamic later.
- In the Loop of that View, insert Types field shortcodes to display any custom field information about each Writer Share.
- If you want to include the parent Writer information alongside the Writer Share fields for this relationship, use Views shortcodes with the $parent operator like this to insert that information in the same Loop:

[wpv-post-title id="$writer"]

- Insert this View in the View of Pitches.
- If you want to display the Writer information separately from each Writer Share, you must create another View of Writer Shares filtered by post relationship like before, and insert Views shortcodes to display information about the parent Writer of each Writer Share in the Loop.
- Once you have those Views showing the correct information, make them dynamic by changing the Query Filter to use a shortcode attribute instead of a single specific Track.
- Use a Content Template like you did before, get the grandparent Track ID using the wpv-post-id shortcode, and pass that value into your Writer Share View's post relationship shortcode attribute, something like this in the Content Template:

[wpv-view name="your-view-slug" wpvprchildof="[wpv-post-id id='$track']"]
#621033

Hi Christian,

Thank you for your help. Unfortunately I really don't get it. 🙁
Just to reiterate: the final view I'm looking for is:
SORT BY CLIENT
Track Title | Alias Title | Pitch Fields | Client | Writer Share Fields | Writers (just the title field)
I have now a view for "Track Title | Alias Title | Pitch Fields | Client " (with sort by client)

"To show fields from the Writer Share post, create a View of Writer Shares, filtered by post relationship. For now, select a specific parent Track. "
OK - no problem

"In the Loop of that View, insert Types field shortcodes to display any custom field information about each Writer Share.
- If you want to include the parent Writer information alongside the Writer Share fields for this relationship, use Views shortcodes "
OK - no problem

"Insert this View in the View of Pitches."
I assume I insert this in the Loop editor (not in one of the 2 templates attached to this view). Of course, when I do this I just get the writer share fields and writer title ([wpv-post-title id="$writer"]) for the SINGLE track I selected above.

Here's where I get really confused:

"If you want to display the Writer information separately from each Writer Share - ???, you must create another View of Writer Shares filtered by post relationship like before, and insert Views shortcodes to display information about the parent Writer of each Writer Share in the Loop. etc...."
I don't understand at all - I need 2 different writer share views? they both sound the same to me as described

I'm sorry, this is very confusing to me.

Thank you!
Scott.

#621074
Screen Shot 2018-03-01 at 1.20.12 PM.png

If you want to display the Writer information separately from each Writer Share - ???
It's a visual difference that can be illustrated by the attached picture. I'm asking how your information will be organized on the front-end of the site for each Writer and his or her Writer Share fields.
1. All Writers are displayed together and all Writer Shares are displayed together, and there is no obvious connection between each Writer and his or her Share fields (row 2).
2. Each Writer is displayed individually with their respective Writer Share information (row 4 in spreadsheet).

While the difference may seem trivial, it is important because it directly impacts the organization of the Views.

#621091

Ah I think I see - and thank you for your patience!

There is a connection between the writers share and the writer.

Each track can have multiple writers and each writer has a "share" of the writing royalties of a specific track.
So:

"Our Great Track" writer 1: Jim - writer 1 share: 60% - writer 2: Jane - writer 2 share: 40%

In addition (and this has already been covered)
Each track has multiple aliases (alternate titles) and each of these aliases can be "pitched" (which has fields like "pitch date") to multiple clients.

Thank you!!!

Scott.

#621135

There is a connection between the writers share and the writer.
Okay great, in that case there is no need to create an additional View just for Writers. In the Loop Output of the View of Writer Shares, you will include shortcodes that display both the parent Writer information and the current Writer Share information. For example:

Writer: [wpv-post-title id="$writer"], Share: [types field="fieldslug"][/types]

Of course, when I do this I just get the writer share fields and writer title ([wpv-post-title id="$writer"]) for the SINGLE track I selected above.
Once you have these Views showing the correct information for the single hardcoded Track, you can make them more dynamic by changing the Query Filter on the View of Writer Shares to respond to a shortcode attribute. We have more information about shortcode attributes and how they can affect filters here:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

The original View is a View of Pitches. From inside that View, you need to show a View of Writer Shares, filtered by parent Track ID. It's not possible to access the grandparent Track ID from the View of Pitches directly, as you've already seen. You must use a Content Template like you did before: https://toolset.com/forums/topic/help-with-a-view/#post-620674
You will create a new Content Template, and move the View of Writer Shares out of the View of Pitches into this Content Template. Then place the Content Template in the View of Pitches where the View of Writer Shares was before. Then within the new Content Template you can access the grandparent Track's post ID, and pass that ID into your View of Writer Shares filter as a shortcode attribute. Then your View of Writer Shares will be dynamic, and respond to different Tracks automatically.

#621503

Hi Christian,

I'm sorry - I've read this over and over and I just don't get it -

I have my View of Writers Share:
--Content selection = "writers share" (the intermediary child CPT between "track" and "writer")
--Query filter = select posts that are children of the Post with ID set by the shortcode attribute wpvprchildof.
eg. [wpv-view name="view-name" wpvprchildof="123"]
--Loop item in View Writers Share = [types field='writers-share3'][/types][wpv-post-title id="$writer"]

OK - good so far right?

NEXT:
Now I create a "Content Template" and insert this view into it - correct?
What do I choose for "usage"? anything?

NEXT:
Insert this Content Template into my View of Pitches - correct?
In the Loop Editor of my "view of pitches" I have (the shortcode for adding the writers content template I just created):
[wpv-post-body view_template="Writers in track alias sort client"]
Is this correct?

NEXT:
In the "Templates for this view" section of the view of pitches, in this content template (the template for getting the writers into this "Pitches view")
What do I put here? currently I have (but it's not working)
[wpv-view name="view-to-show-writer-in-track-alias-sort-by-client" wpvprchildof="[wpv-post-id id='$track']"]

As I say - this is not working - I get "No items found"

This is very confusing.

this link is not that helpful as it doesn't give an example for this situation (Filter by post relationships) it just shows and image of the Query filter screen, but not example code for "Filter by post relationships"
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

Thank you.

Best,
Scott.

#621571

I think I figured it out...finally...

I was under the impression I create a NEW content template (for the writers/ writers share) in ADDITION to the first one I created (which was for track title and aliases) and have both added to the "View of Pitches"

because you said, when I asked how to add writer:
"You will create a new Content Template, and move the View of Writer Shares out of the View of Pitches into this Content Template. Then place the Content Template in the View of Pitches"

I took this literally to mean a new content template for the writers to add to "view of pitches" in addition to the content template I created to add track titles and alias titles.

But I guess I misunderstood this right?
I need to add this:
[wpv-view name="view-to-show-writer-in-track-alias-sort-by-client" wpvprchildof="[wpv-post-id id='$track']"]

to the FIRST content template - not create a new one (for the writers).....
correct?

so my content template within the "View of Pitches" looks like this:

Track: [wpv-post-title id="$track"]<br>
Alias: [wpv-post-title]
[wpv-view name="view-to-show-writer-in-track-alias-sort-by-client" wpvprchildof="[wpv-post-id id='$track']"]

Do I have this right now?

Thank you!!!

#621828

A single Content Template may work just fine, again it depends on visual organization of content. If you would like to put everything online, I will be glad to take a quick look. Provide login credentials for your wp-admin area in the private reply fields here.

#621840

Hi Christian,

Thank you. Things seem to be working OK for now. I'm only displaying the info as a simple table, so one content template seems OK.
I'll open a new ticket if I need more help with this going forward.

Thank you for all your help!
Best,
Scott.