Skip Navigation

[Closed] Displaying checkboxes output

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 11 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by Caridad 11 years, 11 months ago.

Assisted by: Caridad.

Author
Posts
#10908

Hi, I would like to display the output of my checkboxes in a list, or at least separated by commas.

Searching around, the only way that I found to display the checkboxes output using PHP would be to array each option individually like so:

echo types_render_field("my-checkboxes", array("option"=>0));
echo types_render_field("my-checkboxes", array("option"=>1));
echo types_render_field("my-checkboxes", array("option"=>2));

and this will display the value of those that I have checked, but there is no clean way to separate them with this method. There must be a better way to do it.

#10939

Dear Maresca,

You can use a normal wordpress function to do this:

$checkboxes = get_post_meta(get_the_ID(),'wpcf-my-checkboxes');
 var_dump($checkboxes);

Please let me know if there is anything else that I can assist you with.

Regards.
Caridad

#11008

Well, I'm having trouble displaying the actual results on the site. Forgive me, I'm a bit of a novice. This is what I tried:

$checkboxes = get_post_meta(get_the_ID(),'wpcf-my-checkboxes');

if(empty($checkboxes))
  {
    echo("None.");
  }
  else
  {
    $N = count($checkboxes);
    for($i=0; $i < $N; $i++)
    {
      echo($checkboxes[$i] . ", ");
    }
  }

And the output on the site was: Array,

Obviously, I want the actual names of each of the checked checkboxes to display, rather than the word array. How can I accomplish this?

#11010

OK I got it sorted out:

global $wp_query;
global $post_id;
$post_id = $wp_query->post->ID;
$checkboxes = get_post_meta($post_id,'wpcf-my-checkboxes',true);

foreach ($checkboxes as $checkbox) {
    echo $checkbox.", ";
}

Thanks for your assistance!

#11039

Dear Matt,

If you want to get rid of the last comma, try with this code:

echo implode(', ', $checkboxes);

Please let me know if there is anything else that I can assist you with.

Regards.
Caridad

The topic ‘[Closed] Displaying checkboxes output’ is closed to new replies.