Skip Navigation

[Gelöst] Conditional Statement in wpv-for-each

This support ticket is created vor 5 Jahren, 10 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von aaronM-9 vor 5 Jahren, 10 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#1180211

The Toolset documentation says you cannot place conditional statements inside of a wpv-for-each tag and I'm wondering if you have any workarounds for this. In my particular example, I have a field "wpcf-philosophy-secondary" that may contain one or more values. For each of these values, I would like it to display a post excerpt and a link (see below). Do you have any suggestions? Right now it will not function but I cannot think of another way to get it to work without using the wpv-for-each tag. Thanks for any suggestions.

- Aaron

          	[wpv-for-each field="wpcf-philosophy-secondary"]
          		[wpv-conditional if="( $(wpcf-member-philosophy-secondary) eq 'Charlotte Mason' )"]
          			<h3>Charlotte Mason</h3>
          			[wpv-post-excerpt item="846"]
          			<p><a href="[wpv-post-url item="846"]">Click Here to Read More</a></p>
          		[/wpv-conditional]
          		[wpv-conditional if="( $(wpcf-member-philosophy-secondary) eq 'Classical' )"]
          			<h3>Classical</h3>
          			[wpv-post-excerpt item="861"]
          			<p><a href="[wpv-post-url item="861"]">Click Here to Read More</a></p>
          		[/wpv-conditional]
          	[/wpv-for-each]
#1180253

Hi, there is no known workaround other than a fully custom, code-based solution. You can access an array of repeating custom field values using WordPress get_post_meta(), then loop over them using foreach. Here's an example:
https://stackoverflow.com/questions/14912739/repeatable-custom-field-display

Types custom fields use the wpcf- prefix in the database, so prepend wpcf- to the field slug shown in wp-admin. Then you would have to recreate the conditional logic in PHP and return the correct output. The WordPress codex has some examples of custom shortcodes:
https://codex.wordpress.org/Shortcode_API

#1180936

I ended up doing this by creating an additional custom post type and through relationships and views cycling through it that way.