Get group name in acf/save_post action
-
Hello, I would like to have the name of the group when I save a post with ACF with the action acf/save_post. Here is the function I use to send the mail. The email is sent but the $name variable is empty.
How to find the information of the group linked to the post please. Thanks a lot.
add_action('acf/save_post' , 'my_save_post', 15); function my_save_post($post_id) { add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' ); $post = get_post($post_id); $post_url = get_permalink($post_id); $post_title = get_the_title($post_id); $author = get_userdata($post->post_author); $subject = 'Post publish notification - post id : ' . $post_id; $sendmail = get_field('send_email_notification', $post_id); $group_ids = Groups_Post_Access:: get_read_group_ids( $post_id ); $group = new Groups_Group( $group_id ); $name = $group->name; $message = "This message was sent to the following group:" . $name; $users = get_users( array( 'role' => 'administrator' ) ); if( ! empty( $users ) ) { $emails = wp_list_pluck( $users, 'user_email' ); } if ( ($sendmail == '0') || (empty($sendmail)) ) { } else { wp_mail($emails, $subject, $message ); } remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' ); }
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Get group name in acf/save_post action’ is closed to new replies.