Support Forum
Support › MB Term Meta › taxonomy-{taxonomy}-{term} only metabox
Hello,
I need to find a way, how to show metaboxes only on taxonomy single term - taxonomy-{taxonomy}-{term}. Is there any solution? I use MB Term Meta. I try Show and Hide, Include Exclude extensions.
Test code:
add_filter( 'rwmb_meta_boxes', 'prefix_register_taxonomy_meta_boxes' );
function prefix_register_taxonomy_meta_boxes( $meta_boxes ){
$meta_boxes[] = array(
'title' => 'Standard Fields',
'taxonomies' => array('poschodia_retail'), // THIS: List of taxonomies. Array or string
'show' => array(
'poschodia_retail' => array( 22 ),
),
'exclude' => array(
'relation' => 'OR',
'ID' => array( 23 ),
),
'fields' => array(
array(
'name' => 'Featured?',
'id' => 'featured',
'type' => 'checkbox',
),
array(
'name' => 'Featured Content',
'id' => 'featured_content',
'type' => 'wysiwyg',
),
array(
'name' => 'Featured Image',
'id' => 'image_advanced',
'type' => 'image_advanced',
),
array(
'name' => 'Color',
'id' => 'color',
'type' => 'color',
),
),
);
return $meta_boxes;
}
Hi,
Thank you for getting in touch.
You just need to add the setting taxonomies
to show meta boxes and custom fields when editing terms. Using the MB Show Hide or MB Include Exclude to show them on a/some specific terms.
add_filter( 'rwmb_meta_boxes', 'prefix_register_taxonomy_meta_boxes' );
function prefix_register_taxonomy_meta_boxes( $meta_boxes ){
$meta_boxes[] = array(
'title' => 'Standard Fields',
'taxonomies' => array('poschodia_retail'), // THIS: List of taxonomies. Array or string
'fields' => array(
...
),
);
return $meta_boxes;
}
Hi,
taxonomies setting is already in code, but I want to find a way how to show metabox only in one taxonomy term. For example I have taxonomy called "taxonomy". In this taxonomy I have two terms - "taxonomy-term1" and "taxonomy-term2". I need to show metabox only on term called "taxonomy-term1". Is there any way to do it?
Thank you for hint.
add_filter( 'rwmb_meta_boxes', 'prefix_register_taxonomy_meta_boxes' );
function prefix_register_taxonomy_meta_boxes( $meta_boxes ){
$meta_boxes[] = array(
...
'taxonomies' => array('poschodia_retail'), // THIS: List of taxonomies. Array or string
'fields' => array(
array(
'name' => 'Featured Content',
'id' => 'featured_content',
'type' => 'wysiwyg',
// 'visible' => array( 'tag_ID', 22 ),
'visible' => array( 'slug', '1-poschodie' ),
),
),
);
return $meta_boxes;
}
Hi,
Currently, the extension MB Term Meta only supports showing the field on all terms of the taxonomy. I will create a feature request to support showing the field on specific terms, just like 'terms' => array( termID, or termSlug )
.
You can try to create a condition before registering the meta box by coding. For example
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = '';
if( !is_admin() ) return;
$list_term_ids = array(16, 18); // list of term IDs
if( $_GET['taxonomy'] == 'poschodia_retail' && in_array( $_GET['tag_ID'], $list_term_ids ) ) {
$meta_boxes[] = [
'title' => __( 'Term Meta', 'your-text-domain' ),
'id' => 'term-meta1',
'taxonomies' => ['poschodia_retail'],
'fields' => [
[
'name' => __( 'Text', 'your-text-domain' ),
'id' => $prefix . 'text_opthfz8evwb',
'type' => 'text',
],
],
];
}
return $meta_boxes;
}