Skip Navigation

[Resolved] Conditional to check if parent field is empty doesn't work as expected

This support ticket is created 6 years, 2 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Shane 6 years ago.

Assisted by: Shane.

Author
Posts
#1180850

I am trying to:

I have a CPT "Produkt" (products) with a URL-field "Testpage". Also there is a CPT "Angebot" (deal) with a many to many relationship to "Produkt" as child. I made a view where I show "Angebot" from one parent "Produkt". I try to test if the related "Produkt" field "Testpage" is empty or not.

First I followed your documentation and did this:

[wpv-conditional if="( $(wpcf-testpage).id(produkt) eq '' )" debug="true"]Testurl empty[/wpv-conditional]

But even if the Testpage field is NOT empty I get this:

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( $(wpcf-testpage).id(produkt) = '' )
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(wpcf-testpage).id(produkt) = '' )
--------------------
After replacing 1 general variables and comparing strings: ( '' = '' )
	Comparing  to 

But after some experiments I got this working code:

[wpv-conditional if="( '[types field='testpage' item='@produkt-angebot.parent' output='raw'][/types]' eq '' )" debug="true"]Testurl empty[/wpv-conditional]

With this result:

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( '<em><u>hidden link</u></em>' ne '' )
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( '<em><u>hidden link</u></em>' ne '' )
--------------------
After replacing 1 general variables and comparing strings: ( '<em><u>hidden link</u></em>' ne '' )
	Comparing <em><u>hidden link</u></em> to 

Here is a page where I test my code, with a first product "WP Rocket" where there is an empty Testpage-URL and all following product have an non-empty Testpage-URL:

hidden link

Why is the expression

$(wpcf-testpage).id(produkt)

not working?

#1180886

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Helmi,

Its possible that it needs to be evaluated using the empty() function.

Take a look at the link below.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#1-using-the-empty-function

I can see where it should work but could you try using the empty() function on it and let me know the results ?

Also I see where it is not getting the parent value either based on the debug information.

Looking forward to hearing from you.

Thanks,
Shane

#1180893

Hi Shane,

I tried this before without success, but I implemented it for you in the view:

<p>2. Testvariante (wpcf-testpage Test empty):</p>
<p>
  [wpv-conditional if="( empty($(wpcf-testpage).id(produkt)) )" debug="true"]This field is empty or does not exist[/wpv-conditional]
  [wpv-conditional if="( NOT(empty($(wpcf-testpage).id(produkt))) )" debug="true"]This field is not empty[/wpv-conditional]
</p>

The result I got is always "This field is empty or does not exist".

You can see the result on the given site:

hidden link

#1181588

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Helmi,

I was able to replicate the issue and will be making a report to our team.

Thanks,
Shane

#1181660

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Escalated

#1206496

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Helmi,

Just an update here.
Our developers are going to resolve this issue.

However they have posted the workaround at this link here
https://toolset.com/errata/wpv-conditionals-populated-with-types-fields-not-from-current-post-as-at-a-origin-will-fall-back-to-the-current-post-data/

Thanks,
Shane