Skip Navigation

[Resolved] Outputting Toolset Checkbox Group values with PHP

This support ticket is created 2 years, 4 months 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)

This topic contains 3 replies, has 2 voices.

Last updated by Shane 2 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#2416345
Screen Shot 2022-07-12 at 12.55.55 PM.png

Hi, I'm trying to output the data submitted via a cred form into an email that I'm generating in my WordPress site's functions.php file. I'm doing it successfully except when I try to output a checkbox group field.

I've been able to get it to output the word "Array", but that's about it.

I've also tried iterating through the array with a foreach statement, but I'm obviously doing something wrong.

The attached screenshot shows my Field Group setup for the checkbox group submitter-organization-classification.

In my functions.php file, I'm getting the field's values like this:

$submittedBy_org_type = get_post_meta($post_id, 'wpcf-submitter-organization-classification',true);

...but from there, I'm not sure how to break that apart into a comma-delimited list of values in plain English.

I tried:

$org_classification_list = "";
foreach ($submittedBy_org_type as $value) {
                $org_classification_list = $org_classification_list .  $value . ",  ";
            }

...but no luck. Can you give me some guidance on how to do this correctly?

Thanks!
David

#2416359

Shane
Supporter

Languages: English (English )

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

Hi David,

Thank you for getting in touch.

Our Checkboxes values are stored in a serialised format in the database so you will need to make use of our custom function in order to retrieve the value.

Please try the function below.

types_render_field( "my-checkboxes", array( "separator" => ", " ) )

Of course change "my-checkboxes" to the actual slug of your checkbox field.

Thanks,
Shane

#2416381

Thanks Shane!

I didn't have any luck with that the first time around and have a question. I know the types_render_field function is part of the Toolset API. My PHP code is running in my theme's functions.php file. To get that function to work, do I need to call the API somehow?

#2416389

Shane
Supporter

Languages: English (English )

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

Hi David,

Generally this code is meant to be used on a template as it get the value of the custom field from the global post ID.

If you're getting the post ID in the functions.php file then you can manually pass that ID into the function like below.


types_render_field( "my-checkboxes", array( "separator" => ", " ,"item"=>$post_id) )

Where $post_id is the example variable for the post id.

Thanks,
Shane