Skip Navigation

[Resolved] conditional display based on user field

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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 3 voices.

Last updated by Steve 1 year, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2523333

I'm trying to create some content based a value in a custom user field. To get started i'm just testing for the existence of any content at all with this statement before i refine it for specific values. But nothing is displaying as true- Do i have the syntaxt correct
I'm using this in a user record view

[wpv-conditional if="( '[types usermeta="school-levels"][/types]' ne '' )"]
school has a level
[/wpv-conditional]

#2523563

Christopher Amirian
Supporter

Languages: English (English )

Screen Shot 2022-12-28 at 10.29.05.png
Screen Shot 2022-12-28 at 10.31.12.png

Hi there,

Retrieving a custom field is possible only in the context of a view.

I suggest that you add a test page and inside the page, use the block editor to add the view block.

Set the proper custom field as the source of the view and inside the view add the conditional block and set it with the wizard to whatever you need.

Then add a single field block to show the custom field.

If everything works ok click the Three Dots WordPress menu icon at the very top right section of the screen and select the "Code Editor" option and in the changed code you can see the generated shortcode which you can use.

Check the screenshot please.

For more information:

https://toolset.com/course-lesson/using-toolset-conditional-block/

#2524425

Sorry Christopher, I wasn't clear enough here. This is in a view and im using the original views (not block)

Steve

#2525513

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Steve,

The syntax of the conditional statement that you've shared seems correct.

Have you checked the output of the types field shortcode alone, without the conditional statement?
( i.e. [types usermeta="school-levels"][/types] )

I'll also recommend testing the conditional statement with the debugging turned on, to see the exact conditional evaluation that is being processed:
( ref: https://toolset.com/documentation/legacy-features/views-plugin/debugging-views-output/ )


[wpv-conditional if="( '[types usermeta="school-levels"][/types]' ne '' )" debug="true"]
school has a level
[/wpv-conditional]

I hope this helps and please let me know how it goes.

regards,
Waqar

#2525671

It seem like the short code i needed is
[wpv-user field="school-levels"] not [types usermeta="school-levels"][/types]

And so the conditional like this works ok

[wpv-conditional if="( '[wpv-user field="school-levels"]' ne '' )" debug="true"]

school has a level
[/wpv-conditional]

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.