Hide terms on Taxonomy Field
- This topic has 6 replies, 2 voices, and was last updated 2 years, 10 months ago by
Trang Nguyen.
-
AuthorPosts
-
June 11, 2022 at 5:49 AM #36448
Trang Nguyen
ParticipantHi!
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!
June 13, 2022 at 11:13 PM #36460Long Nguyen
ModeratorHi,
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-paginationJune 13, 2022 at 11:25 PM #36461Trang Nguyen
ParticipantHi. 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.
June 14, 2022 at 2:31 PM #36475Long Nguyen
ModeratorHi,
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; }
June 15, 2022 at 5:01 AM #36484Trang Nguyen
ParticipantMany 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.
June 15, 2022 at 11:14 AM #36495Long Nguyen
ModeratorHi,
If you want to add an array in the builder, please follow this documentation https://docs.metabox.io/extensions/meta-box-builder/#dot-notation
June 17, 2022 at 1:07 AM #36543Trang Nguyen
ParticipantThank you. I will check it
-
AuthorPosts
- You must be logged in to reply to this topic.