Skip Navigation

[Resolved] Trying to configure search with relationship CPT fields

This support ticket is created 6 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
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 Christian Cox 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1143919

Tell us what you are trying to do?
I'm trying to configure my grid to allow search for two fields within the parent relationship.
Ie. Units page lists units with details from the one to many parent of Floorplans (bedrooms, floorplan name, availability type, etc.).
I want to search the units list using bedrooms and availability type.

Is there any documentation that you are following?
I've used many videos and documentation pages including Vies Training Course - Part 7: Custom search and a variety of articles from the Support forums.

Is there a similar example that we can see?
hidden link (where search by bedrooms and bathrooms are in the CPT for the model, not the unit for sale)

What is the link to your site?
hidden link

#1144480

I want to search the units list using bedrooms and availability type.
Hi, I understand you want to be able to filter a View of Units by custom field values applied to a related post type. Right now, this isn't possible in Views because you can only apply custom field filters for fields applied directly to the post type being queried. We do plan to include updated related post filtering capabilities like this in an upcoming release, but it's not ready just yet. Until that feature is added, the only way to filter by bedrooms and availability type is to change the Content Selection of the View to display the parent post type, then nest a View of Units inside the Loop of the parent post type View. Add a post relationship filter where the parent post is the current post in the Loop.

This approach can be effective, but it can also cause quirks with results counts and pagination because of the nested View. It also means you won't be able to filter by any Units fields or criteria.

#1144482

Hi Christian,

An interesting idea. I need pagination as well but I don’t care about a count of units.

Are you able to point me to something that can walk me through this?

Another option I was thinking is having two other CPTs for bedrock and types and filtering by the grandparent. Not sure if it would work though.

Thanks,
Chris.

#1144524

Are you able to point me to something that can walk me through this?
I don't have anything at hand, but the general idea is you create a View of the child post type (choose "Show all results" in the popup) and then add a Post Relationship Query filter. The Query Filter should be configured so that the parent post is set by the current post in the loop. Use the Loop Wizard to create an unformatted loop, and insert the post title or post link (whatever you want to show for each Unit result). Then create a View of Floorplans and add your Floorplan custom field filters in the Search and Pagination editor area. Use the Loop Wizard here to create another unformatted loop, and insert the post title temporarily. After the markup is generated automatically, replace the post title shortcode with your View of the child post type.

You can paginate the View of the parent post type, but the number of Units results shown on each page will be inconsistent. You cannot paginate the View of the child post type.

Another option I was thinking is having two other CPTs for bedrock and types and filtering by the grandparent.
If you want to filter by parent and grandparent post type that's certainly possible, but I don't think it applies in this case - you won't be able to filter by individual criteria this way.

#1146000

Hi Christian,

The idea sounds good, but I'm having a hell of a time making it work. Is there a way to have someone help me out with this?

Second, when will the update for Toolset be ready to be able to filter by fields in the parent? To me, this seems like it would be fairly easy, from a coding point of view, you would only need to take each unit and LEFT JOIN the parent (floorplan) which gives you the entire set of elements from both the child and parent to filter by.

Thanks again,
Chris.

#1146063

The idea sounds good, but I'm having a hell of a time making it work. Is there a way to have someone help me out with this?
Yes, if you provide login credentials in the private reply fields here I will be able to take a closer look. Let me know which View(s) I should be looking at, and where I can see them on the front-end of the site.

Second, when will the update for Toolset be ready to be able to filter by fields in the parent?
We do not have a delivery date available yet. I suggest you follow our blog for the most up-to-date information.

#1146544

Okay I can see that you have placed this View on the page: hidden link

I edited this View so that the Floorplans post type is chosen in the Content Selection area. I did this because we want to get all the Floorplans that match the filters first. Then we will display the Units for each of those matching Floorplans in a nested View. I created a View of Units, filtered by post relationship, where the parent post is the current post in the loop:
hidden link

Then I inserted this new View inside the loop of the first View. Take a look and you'll be able to see it in wp-admin. I adjusted the content displayed in each View loop to show the information you want. You may want to modify the formatting, but the information is all there now.

#1146750

Thank you Christian,

That worked perfectly. I now see what you did and it makes sense.

I'd like to know as soon as being able to filter by parent fields is available, however, so I'll keep an eye on the blog page 🙂

Thanks,
Chris.

#1147282

Okay, sounds good. I'm resolving this ticket.

#1147423

Hi Christian,

I've removed all the floorplan content and set it to view only the Unit information from the filter, but it's causing me issues because it's adding an extra div which is screwing up my flex box settings to create a nice grid of all the units. Is there a way to remove the div so all the units are in their own div under the parent unit_grid div?

Example, right now:
<div class="unit_grid">
<div id="wpv-view-layout-CPID418" etc.> (floorplan view)
<div class="avail_column">unit view content</div>
<div class="avail_column">unit view content</div>
<div class="avail_column">unit view content</div>
</div>
<div id="wpv-view-layout-CPID474" etc.> (floorplan view)
<div class="avail_column">unit view content</div>
<div class="avail_column">unit view content</div>
</div>

What I need:
<div class="unit_grid">
<div class="avail_column">unit view content</div>
<div class="avail_column">unit view content</div>
<div class="avail_column">unit view content</div>
<div class="avail_column">unit view content</div>
<div class="avail_column">unit view content</div>
</div>

Please, please, please, please, tell me I can do this, otherwise, I'm so screwed, it's not even funny. I've been working on this little section for 2 weeks now and it should be super, super simple and has turned into a ridiculous nightmare.

Thanks,
Chris.

#1147429

As an alternative, if in the CPT, a new/different floorplan is selected, is there a way to auto-fill certain fields from that new parent relationship?

Example:
Unit 1300 is created (or updated) and floorplan Simple is selected. Simple has 3 bedrooms. Is it possible for Unit 1300 to have a field: bedrooms which will be auto-filled with the bedrooms (3) from the parent floorplan Simple?

Thanks.

New threads created by Christian Cox and linked to this one are listed below:

https://toolset.com/forums/topic/auto-fill-fields-based-on-related-post/

#1147437

Is there a way to remove the div so all the units are in their own div under the parent unit_grid div?
Yes, there is a checkbox in the View editor screen "Disable the wrapping DIV around the View". Try that first.

As an alternative, if in the CPT, a new/different floorplan is selected, is there a way to auto-fill certain fields from that new parent relationship?
I don't understand, sorry! I'll split this question into a separate ticket and ask for some more information.

#1147446

That worked, thank you... phew 🙂

The pagination is weird, like you mentioned, and I understand why. I wish it wasn't so.

Thanks,
Chris.

I'll look at the other thread, if that's possible, I can make it do EXACTLY what I need.

#1149271

Sure, let's follow up there.