Taxonomy fields not clonable?

Support General Taxonomy fields not clonable?Resolved

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #15387
    ToomasToomas
    Participant

    Hello,

    Is that true? At the same time taxonomy_advanced fields are clonable, but I can't set taxonomies to the posts with these. I also noticed that someone here had made a workaround code (save_post) but I can't get it from the Pastebin anymore.

    PS. I use older MB Builder version since the newest one doesn't work with the hierarchical taxonomies at all.

    #15394
    Anh TranAnh Tran
    Keymaster

    Yes, it's true. Taxonomy field when saving will set the post terms. So, it can't be cloned. Only the taxonomy advanced field, where the term IDs are saved, can be cloned.

    #15403
    ToomasToomas
    Participant

    OK, but can you tell me how to solve the problem if I have a hierarchical taxonomy field with select tree and I want to set several terms (together with the children) to the post?

    #15411
    Anh TranAnh Tran
    Keymaster

    If you have to clone the field, then the only solution is using taxonomy_advanced field.

    #15412
    ToomasToomas
    Participant

    Yeah, but taxonomy_advanced doesn't set the terms:(

    #15677
    ToomasToomas
    Participant

    I'm still just curious if there is a workaround to set terms with taxonomy_advanced field?

    #15687
    Anh TranAnh Tran
    Keymaster

    Yes, that can be done with this filter:

    https://docs.metabox.io/actions/#rwmb_field_id_after_save_field

    add_action( 'rwmb_YOUR_FIELD_ID_after_save_field', function( $null, $field, $new, $old, $object_id ) {
        $term_ids = $new;
        if ( $field['clone'] ) {
            $term_ids = [];
            foreach ( $new as $clone_value ) {
                $term_ids = array_merge( $term_ids, $clone_value );
            }
        }
        wp_set_post_terms( $object_id, $term_ids, 'YOUR_TAXONOMY' );
    }, 10, 5 );
    #15690
    ToomasToomas
    Participant

    strange, but it doesn't work. If I activate this, I can't set any other taxonomy's terms either.

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