Value of Select and Radio Elements are not saved to db
-
Hey, love the plugin and been using it forever to make my life easier. I usually only need it for text fields or checkboxes, but with some recent development I need to use the select drop down box.
I realised after a lot of troublehooting, that values of the select (or radio) elements are not being saved to the database, making them return blank when called in the loop. They do not show up when trying to
var_dump
in the loop, unlike all the other custom fields from CMB2 that show up just fine. Only when I manually update the select field usingupdate_post_meta
, it updates the value and shows up.This is my setup in functions.php:
add_action( 'cmb2_admin_init', 'cmb2_retreats_metaboxes' ); function cmb2_retreats_metaboxes() { $prefix = '_retreats_'; $cmb_retreat = new_cmb2_box( array( 'id' => 'lesson_meta_retreat-info', 'title' => __( 'xxxxx', 'cmb2' ), 'object_types' => array( 'retreats', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left ) ); $cmb_retreat->add_field( array( 'name' => 'Teaser Frame', 'desc' => 'xxxxxx', 'id' => $prefix . 'arch-type', 'type' => 'select', 'show_option_none' => false, 'default' => 'arch1', 'options' => array( 'arch1' => 'one', 'arch2' => 'two', 'arch3' => 'three', 'arch4' => 'four', 'arch5' => 'five', 'arch6' => 'six', ), ) ); }
This is a basic setup in the loop im using right now for testing:
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); $arch_type = get_post_meta( get_the_ID(), '_retreats_arch-type', true ); if ( 'arch1' === $arch_type ) { echo 'it works'; } else { // some other PHP code } <?php endwhile; ?> <?php else : ?> <article class="nothing"></article> <?php endif; ?>
Can someone help me out figuring out what might be going wrong? Oh I already disabled all plugins to check for any interference.
Greetings!
- The topic ‘Value of Select and Radio Elements are not saved to db’ is closed to new replies.