Skip Navigation

[Resolved] Conditional statement for usermeta not working

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

Last updated by mikeH-3 5 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1248357

I made this shortcode:

function give_shortcode() {
	return do_shortcode('[types usermeta="online-giving-form-embed-code" output="raw" user_name="[wpv-search-term param=church]"[/types]');  
}
add_shortcode('give', 'give_shortcode');

Then I use this shortcode in my condition:

[wpv-conditional if="( '[give]' eq '' )"]   I am empty [/wpv-conditional]

This means if the GIVE field is not filled out for this user, then it shows "I am empty". This DOES work.

However, if I use

[wpv-conditional if="( '[give]' ne '' )"]   I am NOT empty [/wpv-conditional]

This does NOT work and doesn't show this message on items where the give field is filled in.

What am I doing wrong? What would be the proper code to use to only show something if the field is filled in? It only seems to work for those items where it is empty.

#1248533

That seems like the right syntax, so I suspect something else is going on. Can you turn on debug?

[wpv-conditional if="( '[give]' ne '' )" debug="true"]   I am NOT empty [/wpv-conditional]

Then reload the front-end of the site and tell me what the debug information shows.

#1248563

This is all that appears on the page that IS empty:

I am empty
####################
wpv-conditional attributes
####################
Array
(
    [if] => ( '' ne '' )
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( '' ne '' )
--------------------
After replacing 1 general variables and comparing strings: ( '' ne '' )
	Comparing  to 

The page that isn't empty doesn't show anything.

#1248567

Okay first be sure you have registered give in Toolset > Settings > Front-end Content > Third party shortcode arguments. Next, copy the "give" shortcode and paste it outside the conditionals so I can see what it produces:

Give: [give]<br />
[wpv-conditional if="( '[give]' ne '' )" debug="true"]   I am NOT empty [/wpv-conditional]
#1248569

Ya know what... even if I put in a value to GIVE and go to this page, it still shows that 'i am empty' code. So something deeper is going on.

#1248583

Okay sorry about that. Had to tweak it so the 'empty' really does work. So here is the code that works for EMPTY:

[wpv-conditional if="( '[types usermeta='online-giving-form-embed-code' user_name='[wpv-search-term param=church]' output='raw'][/types]' eq '' )"]
  I am empty
[/wpv-conditional]

If I put NE instead of EQ, it doesn't work still.

#1248593

Copy the code from the conditional and place it just before the conditional so we can inspect it:

User meta info: [types usermeta='online-giving-form-embed-code' user_name='[wpv-search-term param=church]' output='raw'][/types]<br />
[wpv-conditional if="( '[types usermeta='online-giving-form-embed-code' user_name='[wpv-search-term param=church]' output='raw'][/types]' ne '' )"]
  I am NOT empty
[/wpv-conditional]
#1248595

I think I may have gotten it working... I'll keep you updated.

#1248607

Okay I narrowed it down. So this is what I have in my field as data

<script src="<em><u>hidden link</u></em>"></script>

Apparently toolset doesn't view that as something but it also doesn't view it as nothing. Can you help so that if I have a script code in there, it specifically views it as NOT EMPTY for the conditional statements?

#1248613

You could store the URL of the script src in the custom field instead and then build the script tag from that using a custom shortcode. That would get around the problem of not being able to test a script using a conditional.

#1248615

It might not always be a script though, is the problem. Sometimes it will be something else. Is there another way toolset can see it as raw text so it sees that field as filled in?

#1248617

What type of field is this?

#1248675

It is a multiline field. Is there a different one that would work?

#1249501

The wysiwyg field doesnt work either, so what do I do? It's not just <script> code that toolset conditionals don't see. It's ALL html code. Can you provide a workaround or a fix? This is pretty important.

#1250355

It's not just <script> code that toolset conditionals don't see. It's ALL html code.
If you place <div></div> in a WYSIWYG field, it will correctly register not empty. The script tag is the only one that's a problem here. It's a security risk, so there are some precautions built into the system that strip those tags out in some cases. Let me ask my 2nd tier team if there's a better way to handle this. I'll let you know what I find out.