Support Forum
Hi!
When using Taxonomy field (https://docs.metabox.io/fields/taxonomy/), is it possible to hide some of the term that I don't want to use?
For example:
I have a taxonomy with term A, B, C, D, E.
I create a Taxonomy Field as a Checkbox List. I would like to show only the A, B, and C term when editting, the term D, and E will be hidded.
Thank you!
Hi,
Yes, it is possible. You can exclude an array of term IDs with the field setting query_args
. Please read more on the documentation
https://developer.wordpress.org/reference/classes/WP_Term_Query/__construct/
https://docs.metabox.io/fields/taxonomy/#limit-the-number-of-terms-for-pagination
Hi. Thank you for your reply but I dind't mean that.
The links you shared are for front end, using the query_args.
I was asking for the back end, when using a Taxonomy Field of Meta Box, the editors/writers can see and choose only the term A, B, C, not all terms of a taxonomy.
Hi,
The link with instruction is applied to the taxonomy field in the backend. Please try to use this one
function your_prefix_function_name( $meta_boxes ) {
$meta_boxes[] = [
'title' => __( 'My Meta Box', 'your-text-domain' ),
'id' => 'my-meta-box',
'fields' => [
[
'name' => __( 'Taxonomy', 'your-text-domain' ),
'id' => 'taxonomy_ipppnv41eid',
'type' => 'taxonomy',
'taxonomy' => ['category'],
'field_type' => 'select_advanced',
'query_args' => [
'exclude' => 86, // here or use array of term IDs [86, 87, 88]
],
],
],
];
return $meta_boxes;
}
Many thanks for your reply. It works!
I'm using the AIO plugin so I just need to put the 'exclude'/'include' into the Query args setting.
But there is another issue: If I have more than 1 Taxonomy field assigning to the same taxonomy, only the last one saves data when updating the post.
As I have a taxonomy named Characteristic with terms for hair colors, eyes color, ethnicity,... I want to put them into different Taxonomy fields (Hair, Eyes, Ethnicity for example. 3 of them are assigned to Characteristic taxonomy) to make it easy when editing the posts.
I could create multiple new taxonomies for each of the groups but there are only 2 or 3 options for 1 group, making it too many taxonomies to manage.
Hi,
If you want to add an array in the builder, please follow this documentation https://docs.metabox.io/extensions/meta-box-builder/#dot-notation
Thank you. I will check it