CMB2 Taxonomy Select not saving in database
-
I am wanting to display a list of downloads from a custom post type through a specific category ID within a template on different pages.
So far I have created a custom post type, set the fields title and download file(cmb2 metabox). I have created five categories within my ‘forms’ custom post type.
For the website admin to display certain downloads on specific pages I have created a ‘taxonomy_select’ drop down field using CMB2, this worked fine on the initial build but once the user changes the desired category no posts will then show.
It seems that the selection of a new category does not create a new table within the database.
Below is all of the relevant code:
CMB2 metaboxes.php:
$meta_boxes['service_default_custom_fields'] = array( 'id' => 'service_default_custom_fields', 'title' => __( 'Service Custom Fields', 'ct' ), 'object_types' => array( 'page', ), // Post type 'show_on' => array( 'key' => 'page-template', 'value' => 'template-service-default.php' ), 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left // 'cmb_styles' => false, // false to disable the CMB stylesheet // 'closed' => true, // Keep the metabox closed by default 'fields' => array( array( 'name' => 'Downloads Category', 'desc' => 'Select the downloads category.', 'id' => $prefix . 'download_cat', 'taxonomy' => 'form_category', //Enter Taxonomy Slug 'type' => 'taxonomy_select', ), ), );
Template file:
<?php $download_category = get_post_meta(get_the_ID(), '_ct_download_cat', true); ?> <ul> <?php // the query $args = array( 'post_type' => 'forms_pt', 'orderby'=>'title', 'order'=>'ASC', 'posts_per_page' => 7, 'tax_query' => array( array( 'taxonomy' => 'form_category', 'field' => 'id', 'terms' => $download_category, ), ), ); $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : ?> <!-- pagination here --> <!-- the loop --> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); $file = get_post_meta(get_the_ID(),'form_download', true); ?> <li><a>"><?php the_title(); ?></a></li> <?php endwhile; ?> <!-- end of the loop --> <!-- pagination here --> <?php wp_reset_postdata(); ?> <?php else : ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?> <li><a href="/downloads/">View All Forms</a></li> </ul>
[moderated to add backticks for code]
- The topic ‘CMB2 Taxonomy Select not saving in database’ is closed to new replies.