taxonomy-{taxonomy}-{term} only metabox
Support › MB Term Meta › taxonomy-{taxonomy}-{term} only metabox
- This topic has 4 replies, 2 voices, and was last updated 3 years, 8 months ago by
Long Nguyen.
-
AuthorPosts
-
August 20, 2021 at 2:58 PM #30357
[email protected]
ParticipantHello,
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; }
August 20, 2021 at 4:49 PM #30358Long Nguyen
ModeratorHi,
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; }
August 20, 2021 at 5:15 PM #30359[email protected]
ParticipantHi,
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?
August 20, 2021 at 5:29 PM #30360[email protected]
ParticipantThank 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; }
August 21, 2021 at 9:14 PM #30368Long Nguyen
ModeratorHi,
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; }
-
AuthorPosts
- You must be logged in to reply to this topic.