Navigation überspringen

[Gelöst] Cannot test if a post reference field is empty or not in conditional

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: I would like to use a conditional to test whether or not a post reference field has some value.

Solution: Use the Types field shortcode in the conditional instead of the $() syntax:

[wpv-conditional if="( '[types field="product-featured-video"][/types]' ne '' )"]
Product featured video is not empty
[/wpv-conditional]
This support ticket is created vor 5 Jahre, 2 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.

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 scottL-3 vor 5 Jahre, 2 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#1557541

I am trying to:
Display a Featured Video heading and associated video if the post reference field for product-featured-video is not empty. This used to work but, apparently, stopped working at some point, possibly as long ago as the update from the old style relationship to the newer style.

Right below the Featured Project View is a Visual Editor cell containing this:

<div style="text-align:center;max-width:720px;margin-bottom:20px;margin-top:15px;margin-left:auto;margin-right:auto;">
[wpv-conditional if="('1' eq '1')" debug="true"]
<h2>Featured Video</h2>
<div class="youtube-player" data-id="[types field='videoid' item='@product-featured-video.parent'][/types]"></div>
[/wpv-conditional]
</div>

The product-featured-video field is a post reference field and is populated.

Link to a page where the issue can be seen:
versteckter Link
Debug is on so you can see what is happening.

I expected to see:
An h2 title of "Featured Video" and the video.

Instead, I got:
Nothing.

Debug shows:

####################
wpv-conditional attributes
####################
Array
(
[if] => ( $(wpcf-product-featured-video) ne '' )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(wpcf-product-featured-video) ne '' )
--------------------
--------------------
Converted expression: ( '' ne '' )
--------------------

#1559117

Hi, you should be able to replace the $(wpcf-product-featured-video) syntax with the corresponding Types field shortcode in the conditional. Here's an update:

[wpv-conditional if="( '[types field="product-featured-video"][/types]' ne '' )"]
Product featured video is not empty
[/wpv-conditional]

That's assuming the slug is product-featured-video. If not, please adjust the slug as needed. Let me know if the problem is not completely resolved.

#1561549

I am nearly positive I tried that alternative and it didn't work. But I just tried it again and it worked fine. Maybe it was a caching issue last time. Regardless, it is working now. Thanks!