• Resolved Cyroq

    (@cyroq)


    Hi all,

    I want to create multiple instances of checkbox lists. In other words, I want to be able to check multiple boxes in different groups. This is the code structure I’m using:

    array(
    	'name'    => __( 'Genres', 'your-prefix' ),
    	'id'      => "{$prefix}checkbox_list",
    	'type'    => 'checkbox_list',

    I thought I would be able to create several checkbox lists by giving each array a unique id, but changing the id makes the script stop working. To retrieve the values of a checkbox list I use:

    $plots = rwmb_meta( 'your_prefix_checkbox_list', 'type=checkbox_list' );
    echo implode( ', ', $plots );

    Even setting the id and ‘your_prefix_checkbox_list’ to the exact same unique variable doesn’t work. What am I doing wrong?
    Many thanks in advance!

    https://www.ads-software.com/plugins/meta-box/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Do you mean creating a list of checkbox list and then output the result?

    If so, I think it must work. Here is my code:

    $lists = array( 'cb1' => 'Name1', 'cb2' =>  'Name2' );
    foreach ( $lists as $id => $name )
    {
        $fields[] = array(
            'name' => $name,
            'id' => $id,
            'type' => 'checkbox_list',
        );
    }

    To retrieve the meta value, make sure you use the correct ID:

    $plots = rwmb_meta( 'cb1', 'type=checkbox_list' );
    echo implode( ', ', $plots )

    Please check your code, specially the field ID. Maybe it’s the problem where you can’t get the correct value.

    Thread Starter Cyroq

    (@cyroq)

    The problem was indeed with the ID. When I changed the ID’s I didn’t notice that all the checkboxes in the edit-post-page were empty again. Therefore, I didn’t get any results.
    I ticked some boxes after changing the ID, and now it works ?? Thanks for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple instances of checkbox lists’ is closed to new replies.