Custom Fields
Re-Envisioned
Support General Taxonomy fields not clonable?

This topic contains 7 replies, has 2 voices, and was last updated by  Toomas 2 months, 1 week ago.

  • Creator
    Topic
  • #15387
    Resolved
    Toomas
    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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #15394

    Anh 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

    Toomas
    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 Tran
    Keymaster

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

    #15412

    Toomas
    Participant

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

    #15677

    Toomas
    Participant

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

    #15687

    Anh 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

    Toomas
    Participant

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

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.