Hide terms on Taxonomy Field

Support General Hide terms on Taxonomy FieldResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #36448
    Trang NguyenTrang Nguyen
    Participant

    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!

    #36460
    Long NguyenLong Nguyen
    Moderator

    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

    #36461
    Trang NguyenTrang Nguyen
    Participant

    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.

    #36475
    Long NguyenLong Nguyen
    Moderator

    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;
    }
    #36484
    Trang NguyenTrang Nguyen
    Participant

    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.

    #36495
    Long NguyenLong Nguyen
    Moderator

    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

    #36543
    Trang NguyenTrang Nguyen
    Participant

    Thank you. I will check it

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.