Skip Navigation

[Resolved] Conditional using custom field from related post

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

Problem: I would like to create a conditional that tests the value of a custom field in a post that is related to the current post in a View.

Solution:
You must manually write the conditional and use the Types field shortcode as shown here:

[wpv-conditional if="( '[types field="stadt" output="raw" item="@termin-ort.child"][/types]' ne '')"]
Ort: [wpv-post-link item="@termin-ort.child"]
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/customizing-sites-using-php/functions/

This support ticket is created 6 years, 1 month 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 2 replies, has 2 voices.

Last updated by jurgenK-2 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1133650

Tell us what you are trying to do?
I have setup many-to-many post relationships between custom posts. There is an event ("Termin"), and this event has one ore more persons taking part ("personen") and a place ("Ort") where it actually takes place.

Now I want to show the place ("Ort") in a view of the Event ("Termin"). This works fine with this code:
Ort: [wpv-post-link item="@termin-ort.child"]

The next step is to show this line only if there is a place ("Ort") connected with the event ("Termin"). So I tried a condition:
[wpv-conditional if="( $(wpcf-stadt).id(ort) ne '' )"]Ort: [wpv-post-link item="@termin-ort.child"][/wpv-conditional]

This condition does not work. It should read: If the field wpcf-stadt in the connected post "ort" is not empty, please show the place ("Ort") of the event.

How can I achieve this?

What is the link to your site?
hidden link
It is in maintenance mode, if you need access. please let me know.

Thanks Juergen

#1133680

Hi, the conditional GUI doesn't fully support custom fields in related posts right now. We have an internal usability ticket in place to help improve this experience, but for now you can write the conditional manually and use the Types field shortcode like this:

[wpv-conditional if="( '[types field="stadt" output="raw" item="@termin-ort.child"][/types]' ne '')"]
Ort: [wpv-post-link item="@termin-ort.child"]
[/wpv-conditional]

If that doesn't work as expected, add debug="true" to the wpv-conditional shortcode, refresh the page on the front-end of the site, and share the debug output in your next reply.

#1133688

This works. Thank you!