I’m developing a theme-specific plugin to handle most of the theme’s functions. I have a few settings pages, and a couple of them create options by primary categories. For example, a settings page with an option to upload a banner image for each parent category to be used on that category’s archive page. The basic code is like this:
public static function option_fields() {
$prefix = 'otw_category_banner_';
$categories = get_categories( 'parent=0' );
// Only need to initiate the array once per page-load
if ( ! empty( self::$theme_options ) )
return self::$theme_options;
$fields = array();
foreach ( $categories as $category ) {
$fields[] = array(
'name' => __( $category->name, 'cmb' ),
'id' => $prefix . $category->term_id,
'type' => 'file',
'allow' => array( 'url', 'attachment' ) // limit to just attachments with array( 'attachment' )
);
}
self::$theme_options = array(
'id' => 'theme_options',
'show_on' => array( 'key' => 'options-page', 'value' => array( self::$key, ), ),
'show_names' => true,
'fields' => $fields,
);
return self::$theme_options;
}
This code works fine initially, but after the initial options have been created it doesn’t seem to update when, for example, a new parent category is added. I’m a novice developer and first time poster so any help would be greatly appreciated.