Skip Navigation

[Resolved] More complicated View for Toolset many to many relationship

This support ticket is created 5 years 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 7 replies, has 2 voices.

Last updated by Josef Prexl 5 years ago.

Assisted by: Nigel.

Author
Posts
#1406879

Tell us what you are trying to do?
I have CPT Books and Authors. I have Relationship (called Portfolio), one to many (Author can be assigned to one Book, Infinite Books can be assigned to one Author). On CPT detail page with Book (for example here - hidden link) I would like have list all Books from the same Author too

Is there any documentation that you are following?
I read documentation (here https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/) and tried lot of combination, but without success.

Is there a similar example that we can see?
hidden link - here are all Books from the same Author - but on Authors page - it works well here.

What is the link to your site?
hidden link

#1407157

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2019-12-12 at 15.45.16.png

Let me illustrate with an example from my own test site, which has a similar structure, with a Project << Tasks relationship.

The parallel to what you want to achieve (display other books by the same author when visiting a single book) is to display other tasks of the same project when looking at one project.

So you will need a View to display the child post type, i.e. books for you, tasks for me.

That needs a relationship Query Filter to specify the parent (book, or project). But we are going to have to pass what the parent is to the View, using a shortcode attribute. So your Query Filter should look like my screenshot.

See how we are going to use an attribute "wpvrelatedto" to pass the parent post ID.

So, when we come to insert the View into the template for the child posts (books, or tasks), we use the wpv-post-id shortcode to provide the ID of the parent (specified by the item attribute), like so:

[wpv-view name="other-tasks-of-the-project" wpvrelatedto="[wpv-post-id item="@project-task.parent"]"]

If you are not sure of the format for the item attribute, use the Fields and Views button to insert the wpv-post-id shortcode and specify the relationship as the source.

#1407217
template-view.png
display-filter.png

Hi Nigel,
thank you for your quick response.

I set my best after your instructions, but I propably missed something.

Now - all Books are listed in detail - hidden link - not only Books related with concrete Author. Screens from my settings are attached. Do I need another filter?

Could you check my setting, please?

Thank you,
Josef

#1408045

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

What is the slug of your relationship between authors and books?

It surely doesn't include 'task', which is from my project-task example.

Double check the slug of the relationship. Is it just "portfolio"?

In which case this would be what you need...

[wpv-view name="other-books-in-book-detail" wpvrelatedto="[wpv-post-id item='@portfolio.parent']"]

(Note I edited the item attributes to use single quotes so that the double-quotes didn't break those of the wpvrelatedto attribute.)

#1408295

Hi Nigel,
thank you for your check.

Yes - the slug is just "portfolio", you are right - I fixed it.

Now my code is:
[wpv-view name="other-books-in-book-detail" wpvrelatedto="[wpv-post-id item='@portfolio.parent']"]
[wpv-post-featured-image]
[wpv-post-title]

But still I see all books instead of book of one author :/

I´m not sure about view in view structure in this case and maybe template for this view is wrong?

I can send access to admin too.

Thank you,
Josef

#1408423

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

That looks correct, but let me check.

I will mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site.

#1411385

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2019-12-16 at 09.50.40.png

I first noticed that where you had inserted the View in the Beaver template for books you had not included in the wpvrelatedto attribute, which would explain why books by all authors were showing.

Except when I updated that myself, I found it was always returning No results found.

I then tried simply hardcoding an author ID: you'll notice the page still includes the View inserted with wpvrelatedto="76", but that also returned No results found.

So something evidently is wrong.

Editing the post relationship Query Filter for that View, if you try to specify a particular post, there is something odd. The post type offered is only Books, but that doesn't make sense because the View is already displaying Books, so the post type offered should be Author, as you can see in the screenshot (which is how it should look).

So, I'm not sure what has gone wrong with the View, but something has.

Hence I created a new View to demonstrate how it should work, and it does.

You will find a View "Other books by the same author" which currently just outputs the book title, but the filtering is working, so I suggest you update it so that it outputs the book content in the format you require, and then delete the existing View.

#1411511

My issue is resolved now. Thank you!