Skip Navigation

[Resolved] Create a Query Filter using a Custom Field Address

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to list posts which have a custom field value the same as the current post?

Solution:
You need to pass the value of the custom field in the current post to the View which uses that value in a Query Filter for that custom field.

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created 5 years, 6 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.

Our next available supporter will start replying to tickets in about 6.60 hours from now. Thank you for your understanding.

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 2 replies, has 2 voices.

Last updated by andrei-laurentiuP 5 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#1243905

Tell us what you are trying to do?

I have CPT1 and CPT2, both of which record a custom field AddressXY.

I want to create a view for CPT1 which shows CPT2s that share the same AddressXY.

Also, if CPT1 covers a larger area, let's say USA; and CPT2 has New York, I would like to still display CPT2 within the view for CPT1.

Would that be possible?

#1243917

Nigel
Supporter

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

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

You can do the first part of your question, but not the second, or at least not without some extra steps.

If you are displaying a single post of the type CPT1 and you insert a View in the template for those single posts to display CPT2 posts with the same address, then what's required is that you add an attribute to the wpv-view shortcode that inserts the View to pass the address from the CPT1 field to the View which can then be used in a Query Filter to find posts with the same address.

You can read more about that here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

There is currently no ability for partial matches of the address as you describe in the second part of your question, it's not possible.

You could achieve something similar by, for example, creating a custom taxonomy for the States and assigning that to each post, and then if a post is in California you can pass that State term to the View in the same way and have it find posts with the same State. (This could also be done with custom fields rather than a taxonomy.)

#1244944

Thank you, Nigel. My issue is resolved now. Thank you!