Support » Plugin: CMB2 » CMB2 as an Options page – repeatable fields not working

  • Resolved internetfootprint


    I have setup a theme options page and want use repeatable fields, but I can not figure out how to make them work. Can you please provide an example?

    Also I am using the plugin CMB2 Conditionals, but they don’t work. Is there an trick it get them to work on an options page?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Michael Beckwith


    Fast reply is fast. I was reviewing the forums at the time you posted.

    Can you provide the CMB2 configuration you’re using now? I don’t recall seeing any issues with repeater fields in an options page the last time I tried.

    I am using the example here as a starring point, but I can’t seem to figure out how to add a repeated field.

    Do you have an example of a repeatable field using the above?

    Plugin Author Michael Beckwith


    I’d have a look over at for the field types available. Any with a * next to it, is not a field that has repeatable capabilities, but a healthy amount of them do have the support.

    Marking a field as repeatable is done by passing 'repeatable' => true as part of the add_field() method calls.

    $main_options->add_field( array(
    	'name'    => 'Site Background Color',
    	'desc'    => 'field description (optional)',
    	'id'      => 'bg_color',
    	'type'    => 'colorpicker',
    	'default' => '#ffffff',
    	'repeatable' => true
    ) );

    When repeatable, the data gets stored as an array with each field representing an index in the array. Displaying will require foreach loops at minimum, if you’re not wanting to specify indexes at the time of output. Depends on what you do and what you need it for.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘CMB2 as an Options page – repeatable fields not working’ is closed to new replies.