Support

Account

Home Forums ACF PRO Fire action and get other sub field from same repeater parent

Unread

Fire action and get other sub field from same repeater parent

  • I use a repeater field to have groups in a courses post type.

    For example:

    Course one (post):
    Summer group (repeater field)
    Winter group (repeater field)

    Course two(post):
    summer group (repeater field)
    winter group (repeater field)

    Now in every group (repeater field) i have a sub field called “board”,
    which is suppose to act as the group massages board.

    To the point now:
    Every time i update this “board” sub field i want to send mail to all the group members (every group repeater field has a sub field of users which i select the members of the group in) with wp_mail().

    Now first of all i tried just a simple test:

    
    // Send mails to group members if "board" field value is changed
    function my_acf_update_value( $value, $post_id, $field  ) {
        // only do it to certain custom fields
        if( $field['name'] == 'group_board' ) {
            // get the old (saved) value
            $old_value = get_field('group_board', $post_id);
            // get the new (posted) value
            $new_value = $_POST['acf']['field_5d39afec94cf0'];
            // check if the old value is the same as the new value
            if( $old_value != $new_value ) {
                // Do something if they are different
    $multiple_recipients = array(
        '[email protected]',
        '[email protected]'
    );
    $subj = 'The email subject';
    $body = 'This is the body of the email';
    wp_mail( $multiple_recipients, $subj, $body );
    
            } else {
                // Do something if they are the same
            }
        }
    	// don't forget to return to be saved in the database
        return $value;
    }
    
    // acf/update_value - filter for every field
    add_filter('acf/update_value', 'my_acf_update_value', 10, 3);
    

    And it doesn’t send the mail.

    Second i don’t even know where to begin get the value of the “members” sub field of the same group repeater field which the “board” sub field was changed on…

    Can you give me some directions?

    Thanks!
    Ben

Viewing 1 post (of 1 total)

The topic ‘Fire action and get other sub field from same repeater parent’ is closed to new replies.