Jump to content
Sign in to follow this  
zazu

Display multiple checkboxes array

Recommended Posts

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
  }

Share this post


Link to post
Share on other sites

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 by iarp

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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
  }

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.