WPBP / WordPress-Plugin-Boilerplate-Powered

Wordpress Plugin Boilerplate but Powered with examples and a generator!
https://wpbp.github.io/
GNU General Public License v3.0
793 stars 114 forks source link

How to get the cmp2 options page options? #190

Closed MikeiLL closed 3 years ago

MikeiLL commented 3 years ago

Hey, man. Sorry to bother. I've had a quick look at the CMB2 docs and am not quite finding how to access the options set in the cmb2 settings pages:

<div id="tabs-1" class="wrap">
  <?php
  $cmb = new_cmb2_box(
    array(
      'id'         => MMC_TEXTDOMAIN  .  '_options',
      'hookup'     => false,
      'show_on'    => array(
        'key'   => 'options-page',
        'value' => array( MMC_TEXTDOMAIN ),
      ),
      'show_names' => true,
    )
  );
  $cmb->add_field(
    array(
      'name'    => __( 'Videos per paginated segment', MMC_TEXTDOMAIN ),
      'desc'    => __( 'Number if on demand classes to load at a time.', MMC_TEXTDOMAIN ),
      'id'      => 'videos_per_segment',
      'type'    => 'text',
      'default' => 20,
    )
  );

  cmb2_metabox_form( MMC_TEXTDOMAIN . '_options', MMC_TEXTDOMAIN . '-settings' );
  ?>
</div>

When I try to get the options, it just returns the default:

$eod_options = cmb2_get_option( MMC_TEXTDOMAIN . '_options', 'videos_per_segment',
'default one' );
var_dump($eod_options);
$opts = get_option( MMC_TEXTDOMAIN . '_options', 'default too' );
var_dump($opts);

I'm sure I'm missing something simple.

Mte90 commented 3 years ago

Because -options is the metabox ID in CMB not the one with the value. You need to use -settings to get the values.