Skip Navigation

[Resolved] How to display fields from one custom post type using field data in another

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

Problem: I have custom fields in two different post types that contain similar values. I would like to filter post type A by the custom field value in post type B.

Solution: Use a Query Filter that responds to a shortcode attribute, and set the attribute value using the raw types field data from the current post type.

[wpv-view name="your-lodges-view-slug" state="[types field='alaska-field-slug' output='raw'][/types]"]

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

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

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

Last updated by ericE-4 4 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1478605

I have a custom post type "Trip Request". It contains a checkbox field "Alaska" (stores value "alaska" when checked).

I have another custom post type "Lodge" that contains a select field "State", and one of the possible values is "Alaska", which stores the value "alaska" when selected. Lodge posts also contain an "Email address" field.

What I would like to do is display a page that uses the data in the Trip Request post to output content, composed based on the data in related Lodge posts.

For example, suppose I have 100 Lodge posts. Each has an Email address. 10 of them have the State field set to "Alaska". I also have a Trip Request post called "My trip request". When I display the page for the Trip Request, it shows "These Lodges are in Alaska:" followed by a list of the Email addresses of the 10 lodges with State = "alaska"

Can you give me some advice on the best way to accomplish this?

#1479781
Screen Shot 2020-01-26 at 4.05.14 PM.png

Hi, I would set up a View of Lodges and add a Query Filter based on the select field, where the value is set by a shortcode attribute like "states" (see the screenshot above). In the Loop of this View, output the email address custom field and whatever other markup or information you want to include for each item.

Then in the Trip Request template or post body, place the Lodges View using a View shortcode and add the "states" shortcode attribute. Set the value of the states attribute using a Types field shortcode for the checkboxes field, raw output only, like this:

[wpv-view name="your-lodges-view-slug" state="[types field='alaska-field-slug' output='raw'][/types]"]

This filters the View of Lodge posts by the custom States select field, passing the value of the Alaska field from the current Trip Request post into the Query Filter. This is an example of passing arguments to Views: https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/

Let me know if you need more information or if I misunderstood what you want to accomplish.

#1480287

Hi Christian...thanks that helps. I will have a go and open a new ticket if I struggle.

#1480379

My issue is resolved now. Thank you!