• Resolved John_G

    (@john_g)


    Why group field can’t be not repeatable?
    Who needs true group field have to fix CMB2.php:

    CMB2.php
    function render_group($args)

    Wrap the echoing of a button inside such if:

    if($field_group->options('add_button')){
      echo '<div class="cmb-row"><div class="cmb-td"><p class="cmb-add-row">...
    }

    then use

    'add_button' => false

    for field options.

    https://wordpress.org/plugins/cmb2/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Justin Sternberg

    (@jtsternberg)

    If you want a group that’s not repeatable, than it’s likely you want a separate metabox. Can you explain why you would need a non-repeatable group? If it’s to differentiate a section, you could use the title field type to separate them.

    Thread Starter John_G

    (@john_g)

    It does not matter if it is separate metabox or not. The design of the plugin does not allow to save group(if not using type=>group) as a single meta entry. Everything results in a mess of metas. One have to deal with multiple get_post_meta instead of retrieving all the corresponding data in one go.

    You should not overthink anything. Group filed is a group firstly. Repeatable is different story.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    you can get all of the post meta on a post with 1 get_post_meta() call, for what it’s worth, but it fetches EVERYTHING and you’d need to filter out what you don’t need. Just provide the ID of the post and nothing else.

    Thread Starter John_G

    (@john_g)

    Consider such scenario: you need to combine JSON for client side. With single get_post_meta you will have to filter metas by hand and repeat keys (keys for filtering = cmb2 metabox field ids):

    $metas = get_post_meta($id);
    $keys = array_keys($keys_i_need);
    $filtered = array();
    foreach ($metas as $key => $value)
    {
      if (in_array($key, $keys))
      {
        $filtered[$key] = $value;
      }
    }

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Ever find a workable solution for this John_G?

    Thread Starter John_G

    (@john_g)

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Good to know you found something to work. Have a good day.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘type=>group, add_button=>false’ is closed to new replies.