Jump to content

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
  }
Link to comment
https://forums.phpfreaks.com/topic/295227-display-multiple-checkboxes-array/
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
  • Solution

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
  }
This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.