Skip Navigation

[Resolved] Calling custom user checkbox fields

This thread is resolved. Here is a description of the problem and solution.

Problem:
I have created a custom user field called user category which is a checkbox field so a user can tick multiple boxes when registering. If you could help me to get the Custom Field value of the user in the query. If custom field is checkboxes types, how can I check which checkboxes in group are checked?

Solution:
To get the User’s custom field value and to get the selected & saved value for a checkbox using code, we have a way for this as examples in our Types API. You would do it something like below, to insert Types user meta fields using PHP code, use the following function and syntax:

<?php echo(types_render_usermeta( 'field-slug', array( 'arg1' => 'val1', 'arg2' => 'val2' ) )); ?>

Couple more examples:

<?php echo types_render_usermeta( 'my-checkboxes', array( "user_id" => $curauth->ID ) ); ?>
types_render_field( "my-checkboxes", array( "separator" => ", " ) )

Relevant Documentation:
- For more info, please go to this link and Click on MORE and see How to use this field with php:
https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes
Also please see the info at the very top of this page.

- Old ticket: https://toolset.com/forums/topic/how-to-display-types-user-fields-on-author-page/

This support ticket is created 7 years, 1 month 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

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

This topic contains 4 replies, has 2 voices.

Last updated by lolaz 7 years, 1 month ago.

Assisted by: Noman.

Author
Posts
#571702

Im trying to create a function to search for users based on some parameters. I have created a custom user field called user category which is a checkbox field so a user can tick multiple boxes when registering.

In my search form i have added a select field with options which are duplicates of the checkbox values. I now need to check whether the value selected from the dropdown on form submit matches any of the user-category values saved in the database for that user's profile. Could you please advise on the best way to do this?

Also is there a way to dynamically populate my search form drop down with all available select values generated for the user field i created? I have searched the support forums but couldn't find a solution.

Thanks in advance
Lola

#571716

Noman
Supporter

Languages: English (English )

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

Hi Lola,

Thank you for contacting Toolset Support. I am afraid View's does not offer Custom Search on User Views, so we dont have any searching feature for Users yet as you can see in this ticket as well:
https://toolset.com/forums/topic/search-panel-for-user-view/#post-549329

Our doc also point this out:
https://toolset.com/documentation/user-guides/front-page-filters/#custom-search-form
" You can set-up a custom search for any ‘post’ type including ‘pages’, ‘posts’ and all custom post types (but not for users and taxonomy). "

This might be possible using pure Custom coding & custom development and it is out of support policy (https://toolset.com/toolset-support-policy/) . For this, you may contact Toolset recommended service providers to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/

If you would like me to submit this as a feature request, please let me know and I will submit this to our team for further consideration. Thank you

#571848

Hi Noman,

You didnt quite answer my question. I was asking if you could help me with php to get the custom field value of the user in the query. Toolset supports the addition of custom fields to user profiles so surely helping with querying these should not be outside your support policy. If custom field is checkboxes types, how can I check which checkboxes in group are checked?

Thanks

#571863

Noman
Supporter

Languages: English (English )

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

To get the User’s custom field value and to get the selected & saved value for a checkbox using code, sure we have a way for this as examples in our Types API. You would do it something like below, to insert Types user meta fields using PHP code, use the following function and syntax:

 <?php echo(types_render_usermeta( 'field-slug', array( 'arg1' => 'val1', 'arg2' => 'val2' ) )); ?>

Couple more examples:

  <?php echo types_render_usermeta( 'my-checkboxes', array( "user_id" => $curauth->ID ) ); ?> 
 types_render_field( "my-checkboxes", array( "separator" => ", " ) ) 

- For more info, please go to this link and Click on MORE and see How to use this field with php:
https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes
Also please see the info at the very top of this page.

- An old ticket with similar solution:
https://toolset.com/forums/topic/how-to-display-types-user-fields-on-author-page/

Thanks

#571870

Great thanks!