When adding more than one taxonomy
or taxonomy_advanced
fields to a post/page with different and unique ids, all fields simply save the value of the last one present. In the example below, whatever value is selected for category_feed
becomes the saved value for both category_feed
and category_feed_short
regardless of what is selected for category_feed_short
. How do I add multiple category select fields with ability to save a different selection for each?
function stories_custom_fields($meta_boxes) {
$prefix = 'category_feed_short_';
$meta_boxes[] = array(
'id' => 'category_feed_short',
'title' => 'Article feed by category - Short format',
'context' => 'normal',
'priority' => 'default',
'autosave' => true,
'post_types' => array('page'),
'include' => array(
'template' => array('page-originals-single.php')
),
'fields' => array(
array(
'id' => $prefix . 'headline',
'name' => 'Headline',
'desc' => 'Default: Find out more',
'type' => 'text',
),
array(
'name' => 'Category',
'id' => $prefix . 'select',
'type' => 'taxonomy_advanced',
'taxonomy' => 'category',
'field_type' => 'select_advanced',
'multiple' => false
)
)
);
$prefix = 'category_feed_';
$meta_boxes[] = array(
'id' => 'category_feed',
'title' => 'Article feed by category - Article format',
'context' => 'normal',
'priority' => 'default',
'autosave' => true,
'post_types' => array('page'),
'include' => array(
'template' => array('page-originals-single.php')
),
'fields' => array(
array(
'id' => $prefix . 'headline',
'name' => 'Headline',
'desc' => esc_html__('Default: A deeper look'),
'type' => 'text',
),
array(
'name' => 'Category',
'id' => $prefix . 'select',
'type' => 'taxonomy_advanced',
'taxonomy' => 'category',
'field_type' => 'select_advanced',
'multiple' => false
)
)
);
return $meta_boxes;
}
add_filter('rwmb_meta_boxes', 'stories_custom_fields');