Skip Navigation

[Resolved] Search distance filter on parent view – show related child posts

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/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by georgeY-3 1 year, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2514127
distributor inventory filter.png

Tell us what you are trying to do?
I have two CPTs: Distributors and Inventory Products.
I have a relationship between them called Distributor Inventory.
I have the Distributor view set up with a map and search by distance. It works as intended.
Now I want to show all the Distributor Inventory products related to the Distributors that are shown. Multiple Distributors can be shown in the search, so multiple Distributor Inventory products should be shown. I've added a filter to the second view (Distributor Inventory) but it doesn't filter.

An alternative could be 1) searching to show the Distributors, then 2) clicking one of them to show their Distributor Inventory products on the same page. I like both methods and ideally would like to know how to do it both ways if possible.

Is there any documentation that you are following?
https://toolset.com/course-lesson/creating-a-custom-search/#how-to-search-by-post-relationships
https://toolset.com/course-lesson/how-to-set-up-post-relationships-in-wordpress/
https://toolset.com/course-lesson/displaying-related-posts/?utm_source=plugin&utm_medium=gui&utm_campaign=blocks
https://toolset.com/forums/topic/filter-a-view-with-multiple-relationships/
https://toolset.com/forums/topic/search-filter-with-two-post-relation-ships/
https://toolset.com/course-lesson/using-post-reference-field-to-set-up-one-to-many-relationships/

Is there a similar example that we can see?
I haven't found one.

What is the link to your site?
hidden link

With the filter above we should see only one Distributor Inventory product at the bottom. I have only 3 products added right now, one for each Distributor.

P.S. My ultimate goal is to have this interact with WooCommerce product variations at some point. If I can include this on a product page, perhaps I can have it update the Distributor Inventory to only show the products related to the WooCommerce variation selected, and also for the location they have chosen. I don't know if I'm dreaming the impossible or if that can be accomplished with some custom JS or PHP... I'd be open to hiring someone for this if necessary.

#2514337

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

To achieve what you're planning, you'll need to nest another view that shows the related 'Inventory Products' posts, within the loop of the main view that shows the 'Distributors' posts.

Nesting of blocks-based views is not supported, so the second child view will need to be created using the classic/legacy editor.

You can go to WP Admin > Toolset > Settings > General and select the option "Show both the legacy and Blocks interface and let me choose which to use for each item I build" for the editing experience.

After that, you'll see the option to add classic views from WP Admin > Toolset > Views.

You'll find the guides on using the classic views here:
https://toolset.com/documentation/legacy-features/views-plugin/
https://toolset.com/documentation/user-guides/views/

As a result, your visitors will be able to use the main view's search form to search and narrow down the 'Distributors' posts. And within the results container for each 'Distributors' post, the child view will show their related 'Inventory Products' posts.

I hope this helps and please let me know if you have any follow-up questions.

regards,
Waqar

#2514573

OK, I will give the classic editor a shot. Do you have any input or advice on what I would like to do with WooCommerce? Do you think this is possible?

#2514659

Do I need to design the parent (Distributor) view in the block editor? If so, how do I add the classic view to the loop of it? Here (https://toolset.com/documentation/legacy-features/views-plugin/using-a-child-view-in-a-taxonomy-view-layout/#adding-a-view-to-a-view) it says that I add it to the loop output, but I don't see a loop output option in the block editor. I'm assuming you meant to tell me to create the parent view in the classic editor, as well as the child view?

Also, do I need to include a filter on the child view, or will it filter automatically according to what is in the parent view?

#2516233

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

blocks-view-loop.png

Thanks for writing back.

For the WooCommerce product variations, the post relationships can't distinguish between them. This means that any relationship that you'll create with a product, will be formed with that product as a whole and not with any particular variation.

If you need to connect different versions of products with distributors posts, it would be best to add them as individual products and not as the same product's variations.

As for the nested views, it is your choice, whether you'd like to use the blocks view or the classic/legacy view for the parent one. But the one that is being nested inside (i.e. the child view) should be a classic/legacy view.

Tip: If you don't have a personal preference or don't specially need any particular feature from the blocks based views, it would be simpler to create both parent and child views using the classic/legacy editor, when nesting is involved.

In the context of the blocks based views, anything that you'll place within the "View Loop" block is within the loop of the view.
( example screenshot attached )

#2516439
toolset child view products filter.png

OK, I got the nested child view inside the parent view with a search. The child only displays products when one distributor result is displayed in the parent view. It won't show products for multiple distributors in the search. Is there a way I can change that? I've tried changing the filter options, but nothing worked. I did double check that the relationship is one distributor to many products.

#2519793

I finally figured it out. I needed to use the classic editor for both views and insert the child view into the loop of the first view. I just needed to spend some time messing with it to get it to work.

It doesn't do what I originally intended, which is display a single view of all the products for all the locations searched for below the list of locations, but it works having the views under each location. I'll just need to figure out how to format everything now.

My issue is resolved now. Thank you!

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