Skip Navigation

[Resolved] How do I get Toolset Author checkboxes values in php?

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Shane 3 years ago.

Assisted by: Shane.

Author
Posts
#2014659

I REALLY need your help here.

I have created a Toolset custom field for all users. This is a Checkboxes field.

How in the world do I get the values from this checkboxes field for a given user in php code?
Lets say I want to get the checkboxes values for the user with ID 1. What code do I need to write to get the selected values from the checkboxes field?

Right now, i have tried using this code (checkboxes field slug is called "udbringer-til", and i want to get values for user with ID 1):
get_user_meta(1, "udbringer-til", true);
But does not work.

#2014929

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Anders,

Thank you for getting in touch.

For this I would recommend using the function in the documentation below.
https://toolset.com/documentation/customizing-sites-using-php/functions/

We have the types_render_usermeta() function exactly for this scenario.

Please let me know if this helps.
Thanks,
Shane

#2014933

Shane please, you will have to be MUCH more specific. I have NO idea where to start with that.
Please see my code. Why does that not work - and what would i have to write to make it work? I have tried to be as specific as possible.

By the way, when i used support a couple of days ago, i could chat directly with one of your colleagues. That was incredibly useful. Why cannot use the chat for support?

#2014943

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Anders,

Why cannot use the chat for support?

If a supporter for chat isn't available at the time when you open the ticket then the option won't appear.

The documentation that i've provided gives an example usage of the function.

Here is the example below.

$my_values = types_render_field( "udbringer-til", array( "separator" => ", " ) );
echo $my_values;

The function will return the contents of the my-checkboxes custom field as a comma separated string and i'm printing out that value with the echo function.

You can also pass any of the attributes of the checkboxes field into the function as well. If you have a look at the link below you will see the options that are available.
https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes

Please let me know if this clarifies for you.

Thanks,
Shane

#2014963

Shane, Thanks for a fast and very helpful reply. I have gotten it to work now!
However, i am not sure if i can use this solution for the use case i need it for.

Here is what i need to do.
So all users has this checkbox field, "Udbringer-til" (which means "city"), so let us call the field "city" to make it easy.
Now what i need to do is that a visitor can make a search for a city. He searches for "New york", now i need to get all posts from all users that has checked New York in the check boxes. Can you help me with how I would archive this? I am not sure i can use this types_render_field for this use case?

#2014993

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Anders,

Are you using our Views plugin to list out the posts?

This case sounds like you will need to create a search view that will allow you to filter posts by the city, assuming that the city is also on the post itself.

https://toolset.com/course-lesson/creating-a-custom-search/

Thanks,
Shane

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