Skip Navigation

[Resolved] Conditionally display content based on custom fields value

This support ticket is created 3 years 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.

This topic contains 2 replies, has 2 voices.

Last updated by morenoT 3 years ago.

Author
Posts
#2354185

Hi,
i'm trying to conditionally display content in a custom template based only if a custom user field is equal to a custom post field. Following some posts I've tried this:

[wpv-conditional if="('[types field='codice-obiettivo-strategico'][/types]' = '[types usermeta="codice-gruppo-di-lavoro-assegnato"][/types]')' ]
[cred_child_link_form form='349' parent_id='-1' text='Aggiungi una priorità' target='_self']
[/wpv-conditional]

But it works randomly. Sometimes hide, sometimes not. What am I wronging?

Thanks a lot.

Moreno

#2354285

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

Working randomly doesn't sound right, as the conditional shortcode is evaluated on the server as the page is being prepared and isn't subject to the same problems that can arise running code on the front end where the run order may not be guaranteed.

Working or not working sounds more like an issue with the underlying data.

The first thing you can do is add the attribute debug="true" to the wpv-conditional shortcode, which will display some debugging info on the page that should help identify why the condition passed or failed.

Note, also, you need to be careful with single and double quotes. The if attribute argument should appear inside double quotes, meaning that all interior quotes within the argument must be single quotes (otherwise the close the if attribute prematurely). It looks like your types usermeta shortcode is using double quotes, so change those to single quotes, e.g.

[wpv-conditional if="('[types field='codice-obiettivo-strategico'][/types]' = '[types usermeta='codice-gruppo-di-lavoro-assegnato'][/types]')" ]
#2354591

Hi,

thanks a lot for your suggestion. It drive me towards the final solution. It needs also the parameter current_user='true' in the types usermeta shortcode. Now it (seems) working!

My issue is resolved now. Thank you!