Custom Fields
Re-Envisioned
Support MB Custom Taxonomy Set Taxonomy Advanced as Taxonomy

  • Creator
    Topic
  • #32762
    Liam Colman
    Participant

    Hi there

    I have a number of Taxonomy Advanced custom fields to assign ingredients to a recipe. These are placed in groups. What I would like to do is also assign the term selected with the Taxonomy Advanced field as post terms. Is there a snippet on how to do this?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #32770
    Long Nguyen
    Moderator
    #32810
    Liam Colman
    Participant

    Thanks. I'm at a bit of a loss here. This is what I currently have:

    add_action( 'rwmb_after_save_field', function ( $null, $field, $new, $old, $post_id ) {
    
        $food_zutat_02 = rwmb_meta( 'food_zutat_02' );
        $zutat = isset( $food_zutat_02[$artikel] ) ? $food_zutat_02[$artikel] : '';
        $taxonomy = 'zutat';
        wp_set_object_terms( $post_id, $taxonomy, $zutat );
        
    }, 10, 5 );

    food_zutat_01 is the group and artikel is the item I want to be added to the taxonomy zutat.

    #32825
    Long Nguyen
    Moderator

    Hi,

    For example, I have the group field with ID food_zutat_01 and the taxonomy_advanced subfield with ID artikel. The code below will help you to set the post category after saving the group value.

    add_action( 'rwmb_food_zutat_01_after_save_field', function( $null, $field, $new, $old, $object_id ) {
        wp_set_object_terms( $object_id, intval( $new['artikel'] ), 'category' );
    }, 10, 5 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.