Skip Navigation

[Closed] Conditional Checkboxes with Userfields

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 1 reply, has 1 voice.

Last updated by Christopher Amirian 1 month ago.

Assisted by: Christopher Amirian.

Author
Posts
#2820215
Screenshot 2568-08-15 at 10.57.43.png
Screenshot 2568-08-15 at 10.58.12.png

Tell us what you are trying to do?

I have User Custom Fields as checkboxes. Each checkbox represents a business. When a checkbox is checked, a message for the specific business should appear. This works with only one checkbox, but if I choose 2 or more it breaks. Cannot find the documentation to enable ANY checkbox. Here is the code

[wpv-conditional if="( '[types usermeta='enabled_programs' separator=', ' current_user='true'][/types]' eq '[wpv-post-taxonomy type='company' format='slug']' )"]
      <span class="enrolled-badge">[wpml-string context="wpv-views"]ENROLLED[/wpml-string]</span>
 [/wpv-conditional]

I need it to display the ENROLLED message for each business checked.

Note how in the attached screenshot, one image displaying two busineeses (two checkboxes ticked from the user profile) is missing the label "ENROLLED" while the screen with only one business (only one checkbox ticked from user profile) shows the label

#2820605

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Welcome to Toolset support. According to the documentation below you might be able to use the CONTAIN operator:

https://toolset.com/documentation/legacy-features/views-plugin/displaying-taxonomies-conditionally/

Example (adjust slugs and the number of options). Here company is your taxonomy; enabled_programs is the user checkboxes field:

[wpv-conditional if="(
    CONTAINS(#(company),'[types usermeta="enabled_programs" option="0" current_user="true"][/types]')
    OR CONTAINS(#(company),'[types usermeta="enabled_programs" option="1" current_user="true"][/types]')
    OR CONTAINS(#(company),'[types usermeta="enabled_programs" option="2" current_user="true"][/types]')
    /* add one OR branch per option you use in the user field */
)"]
  <span class="enrolled-badge">ENROLLED</span>
[/wpv-conditional]

Notes:

- #(company) is the built-in macro that returns the current post’s company terms; CONTAINS is the documented way to check a specific term (see the “specific term” example).
Toolset

- [types usermeta="enabled_programs" option="N" …] outputs the value of option N if it’s checked, or empty if not.
For more information: https://toolset.com/documentation/customizing-sites-using-php/functions/

Thanks.

The topic ‘[Closed] Conditional Checkboxes with Userfields’ is closed to new replies.