zazu Posted March 14, 2015 Share Posted March 14, 2015 Hi there guys, I've made some new checkbox fields in my wordpress template using Meta box. Now i want to display those selected checkboxes in the forntend, but it will display only the first checkbox that i've checked, not the other ones. The problem seems to by the array functions that displays only the first checkbox. I'll put bellow the codes that i've been using: This is the code from the meta-box-config.php // General ////////////////////////////////////////////////////////////////////////////////////// array( 'name' => 'Genearal', 'id' => "{$prefix}utilitati_general", 'clone' => false, 'type' => 'checkbox_list', 'options' => array( 'Curent Electric' => __('Curent electric','locality'), 'Telefon' => __('Telefon','locality'), 'Apa' => __('Apa','locality'), 'Gaz' => __('Gaz','locality'), 'Cablu TV' => __('Cablu TV','locality'), 'Canalizare' => __('Canalizare','locality') ), 'std' => false ), This is the code from the frontpage // General ////////////////////////////////////////////////////////////////////////////////////// $locality_utilitati_general = get_post_meta($post->ID, 'locality_utilitati_general', true); if(!empty($locality_utilitati_general)) { ?> <?php _e('General: ','locality'); ?><?php echo implode(',', $_POST['locality_utilitati_general']); ?> <?php } Quote Link to comment Share on other sites More sharing options...
iarp Posted March 15, 2015 Share Posted March 15, 2015 (edited) From http://codex.wordpress.org/Function_Reference/get_post_meta you'll see that you're passing true to the third parameter which states: (boolean) (optional) If set to true then the function will return a single result, as a string. Without a wordpress to test on, i would loop over whatever is returned when that third parameter is set to false and see what is returned. I would expect the boxes you've checked to be returned. However if everything was returned, i would expect some kind of flag that lets you know it was checked. Edited March 15, 2015 by iarp Quote Link to comment Share on other sites More sharing options...
zazu Posted March 15, 2015 Author Share Posted March 15, 2015 Hi, thx for your answear, And what i should change in my code, because i tried to set from true to false and displays only array. Quote Link to comment Share on other sites More sharing options...
Solution zazu Posted March 15, 2015 Author Solution Share Posted March 15, 2015 Hi thx for help, i've solved my problem. The modified code is below: // General ////////////////////////////////////////////////////////////////////////////////////// $locality_utilitati_general = get_post_meta($post->ID, 'locality_utilitati_general', 0); if(!empty($locality_utilitati_general)) { ?> <?php _e('General: ','locality'); ?><?php echo implode(", ", $locality_utilitati_general); ?> <?php } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.