Skip Navigation

[Resolved] Filter view by relationship parent

This support ticket is created 5 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)

This topic contains 4 replies, has 2 voices.

Last updated by Christian Cox 5 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1137382

Hi,

I have a custom post type accommodation.
I've also another custom post type "quote" with a relationship.

In the accommodation post I'm the author
In the quote post the author is the user (he creates a new quote with a CRED form)

I'm trying to create a view to display only the quotes linked to the my accomodation.
I used the "author" filter to display the quotes but I not see any one because I'm not the author of the quote post.

How can I filter the view to see only the quote linked to my accommodation post (is not one accommodation post, I've many of them)? I tried other filter but nothing of them works.

#1137800

Hi, I would do this with 2 nested Views.
- Create a new View of Quotes and in the popup menu choose the option "Show all results". In Query Filter section, add a new Post Relationship filter. In the filter options choose the Accommodation / Quote relationship, and choose "set by the current post in the loop".
- Create a new View of Accommodations and choose the option "Show all results". Find the Query Filter section and add a post author filter. If you want everyone to see YOUR accommodation, set the post author ID to be your User ID. Otherwise choose the current logged-in User, and each User will only see quotes for his/her Accommodation posts. In the Loop Editor, insert the View of Quotes inside the wpv-loop tags, so a list of Quotes will be shown for each Accommodation.
- Place the View of Accommodations on a custom page.

Let me know if I've misunderstood what you want to accomplish.

#1139202

Sorry I tried but not finding the right solution.
It not seem to works.

#1139206

Ok, now it work, i not set the accommodation in the second view.

Now I've a list of all my accommodation and for each one the quotes.

But could be better to have all quotes togheter and not subdivided by accommodation. Is it possible? Of course, only yhe quotes relative to mine accommodation but not subdivided. As a unique list...

#1139778

If you want to display the Quotes in a single list without subdivision, you can create the list container in the View of Accommodations like this:

[wpv-items-found]
	<!-- wpv-loop-start -->
	<ul class="wpv-loop js-wpv-loop">
		<wpv-loop>
			[wpv-view name="Your Quotes View"]
		</wpv-loop>
	</ul>
	<!-- wpv-loop-end -->
[/wpv-items-found]

Then in the Quotes View, create each list item like this:

[wpv-items-found]
	<!-- wpv-loop-start -->	
		<wpv-loop>
			<li>Quote</li>
		</wpv-loop>
	<!-- wpv-loop-end -->
[/wpv-items-found]

Choose the option "Disable the wrapping DIV around the View" in the Quotes View. This is the simplest way to create one single list, not subdivided. However, it doesn't work well with sorting, pagination or some AJAX features.

If you want to use sorting and pagination more effectively, then you cannot use two nested Views. One View must be used instead. Add a custom filter query to a View of Quotes. First you would have to query all of the author's Accommodations posts, then use the post relationships APIs to get the related Quotes. We have documentation for the required APIs here:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

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