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.
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
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?
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!
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