Skip Navigation

[Resolved] Shortcodes for Related Data Already Displayed?

This support ticket is created 2 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 12 replies, has 2 voices.

Last updated by Luo Yang 2 years ago.

Assisted by: Luo Yang.

Author
Posts
#2300365

Tell us what you are trying to do? Discover whether there are shortcodes for views/tables already generated by Toolset.

Is there any documentation that you are following? nothing found.

Is there a similar example that we can see? N/A

What is the link to your site?N/A

I've noticed that 90% of the views I need to create already exist within toolset. When I examine a specific piece of data (I.e. a record on a custom content type), I can see all the relationships and there also see all the related records (and even choose which fields to display). Most of these views (minus some styling) are exactly what I'm needing to create on those content pages.

For example, I'm looking at a Year record (this is a yearly event page), and I can see all the people that attended due to the relationship. this is the same table I need to present on that Year's page (a list of attendees). Is my only choice to create that view from scratch? or is there a way to access the code that has essentially already created a view for that record?

#2300701

Hello,

I suggest you try these:
1) Create two custom post types:
- Year
- attendees

2) Setup one-to-many relationship between post types "Year" and "attendees"

3) Create a post view:
- Query "attendees" posts
- Filter by relationship between post types "Year" and "attendees"
- In view's loop, display the "attendees" post information

4) Create a content template for single "Year" post
https://toolset.com/course-lesson/creating-templates-to-display-custom-posts/
And display the post view's shortcode of step 3)
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-view

#2301103

Thank you. That was my plan. I was just hoping there was a shortcut since that information is already presented in the admin interface when I look at any individual Year post. Toolset is obviously already creating a "view" of some kind there that includes exactly the info I want. Was hoping there was a shortcode or something that could access it so I wouldn't have to reinvent the wheel.

Consider this a feature request. If Toolset is already constructing these queries/views, why not make them accessible for use?

#2301281
toolset yearsinvitees view creation.png
toolset year registrants admin area 2016.png

I'm actually not able to get this to work. I had previously set most of this up and I'm able to build views that have direct one-to-many relationships successfully. However, this one has me stumped. The Year to Invitee relationship is actually a "many to many" relationship (since Invitees may attend multiple years). As such, there as a "YearRegistrants" intermediary table set up to account for this. I've tried different combinations of settings and am unable to get the query to produce any results. I'm attaching three screen shots.

The first one is of the results showing the the Admin view of the Year post for 2016. It shows that a list of people who attended that year is visible, along with the related fields.

The second shows how I've set up the view that shows the message that it produces zero results. Note that I've also tried checking the "Years Registrants Intermediary Posts" box and gotten the same results.

The last screen shot shows the 2016 page. I've successfully listed all the "teams" from 2016 (a simple one to many relationship). But the "No Items found" message is from the Invitee view mentioned.

#2301301
toolset yearsinvitees view creation with both boxes checked.png

I've also tried checking both the Invitee and Years Registrants Intermediary Posts in Content Selection which seems to bring up a logical choice of showing Invitee information through the Years Registrant relationship (see screenshot) but it also yields not results.

#2301581

Please share your website credential in below private message box, also point out the problem page URL and view URL, I can setup a demo for you

#2301705

Thanks for the details.

I assume your are going to display 4 custom fields from 3 different post types:
- invitee-first-name( post type "Invitees")
- last-name(post type "Invitees")
- registrant-nickname(post type "Years Registrants Intermediary Posts")
- puzzling-team-name(post type "Team")

Those custom fields are from different post types, you can not display them directly.

I have done below modifications in your website:
1) Create a content template "Invitee information":
hidden link
Display the related "Team name" field with shortcode:
[types field='puzzling-team-name' item='@puzzling-team-invitee.parent'][/types]

2) Edit the post view "inviteesyeartest":
hidden link
- In section "Content Selection", choose option "Years Registrants Intermediary Posts" only
- in section "Loop item in inviteesyeartest"
Change the codes as below:

<td>[types field="invitee-first-name" item="@year-registrant.child"][/types]</td>
<td>[types field="last-name" item="@year-registrant.child"][/types]</td>
<td>[types field="registrant-nickname"][/types]</td>
<td>[wpv-post-body view_template="Invitee information" item="@year-registrant.child"]</td>

Since those custom fields are from 3 different post type, only the soryby of field "registrant-nickname" will work, other sortby won't work as expected

#2302099

I am very confused by this. If it's not possible to display fields from different post types, how is Toolset doing it in the Administrative section of the web site? (see my screen shot above)

Unfortunately, this solution will not work as the primary sort of this table of data must be the Last Name field (Invitees need to appear in alphabetical order). The most important information in this query is the Invitee information (First Name and Last Name), not the Nickname.

Also, I see that you removed the links. It's imperative that the First Name and Last Name fields be linked to the Invitee content. Ideally, the Team Name would be as well, but First Name and Last Name linked to Invitee content is not optional.

I was told when I purchased Toolset that it could readily display data from related tables. It's disappointing to learn that it cannot.

Where can I find documentation/tutorial on how you brought in related fields? For example "[types field="invitee-first-name" item="@year-registrant.child"][/types]"

#2302123

Additionally, the pagination for the view is still not displaying.

#2302127

Also, not sure if this is related, but I'm no longer able to turn on the Divi Builder on that page.

#2302811

There are lots of questions in this thread, I am trying to answer them one by one:
1) If it's not possible to display fields from different post types, how is Toolset doing it in the Administrative section of the web site?
Yes, it is possible to display fields from different post types, but you need to display them on post type relationshio, and I have setup a demo in your website:
https://toolset.com/forums/topic/shortcodes-for-related-data-already-displayed/#post-2301705

Did you check the result here?
hidden link

Q2) The most important information in this query is the Invitee information (First Name and Last Name), not the Nickname.
Toolset Blocks plugin is using WP_Query to query posts
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
if you want to sort the results by custom fields, you need to setup the custom fields in same post type.

In your case, the custom field "invitee-first-name" is in custom post type "Invitees", then you need to setup the post view to query "Invitees" posts, and display custom fields of related posts by post type relationship

Q3) Where can I find documentation/tutorial on how you brought in related fields?
Please check below document:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

For DIVI issue, please create new ticket for the new issue.

#2303079

I did, indeed, look at what you had done. That was what my feedback was based on. I originally explained I was creating primarily a list of attendees, but you focused it on the Nickname/Intermediary post type, thus my confusion.

I've still not received an explanation for why pagination tools are not showing up in the view, despite Pagination being turned on.

My understanding from your explanation is that the related data can be shown in relation to any of the different post types, however the only columns that can be sorted are the ones from the "primary" post type being queried. Is that correct?

If so, how do I turn off the "clickable header" on the columns that can't be sorted? When setting up the view, there was only one choice to turn sorting on for all columns or not. Leaving that features on for columns that cannot be sorted will be confusing to the user. They will a) assume if they are clickable they can be sorted and b) clicking on them leads to a "no results found".

Thank you for the link to the documentation about related fields.

#2304683

Yes, you are right, you can only sort/filter the results by the same post type("primary" post type being queried).

For other issues, I have tried again the credentials you provide above, it does not work, I get below error message:
Error: The password you entered for the username TempAdmin is incorrect
Please check it, make sure your website is ready for debug.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.