Created
February 5, 2020 14:25
-
-
Save pavlo-bondarchuk/8eb478ce8b6ff87eea9e73898279d81a to your computer and use it in GitHub Desktop.
HOW TO USE ADVANCED CUSTOM FIELDS TO CREATE USER GROUPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://www.quickcleancode.com/how-to-use-advanced-custom-fields-to-create-user-groups/ | |
| add_action('publish_post', 'notifyauthor'); | |
| function notifyauthor() { | |
| $loop = new WP_Query(array('post_type' => 'groups', 'posts_per_page' => -1, 'order' => 'ASC')); | |
| while ($loop->have_posts()) : $loop->the_post(); | |
| if(have_rows('members')): | |
| while (have_rows('members')) : the_row(); | |
| $author = get_sub_field('member'); | |
| $author_id = $author['ID']; $leader = get_field('group_leader'); | |
| $leader_id = $leader['ID']; | |
| $temp = get_field('temp_group_leader'); | |
| $temp_id = $temp['ID']; | |
| $current = get_current_user_id(); | |
| if($author_id == $current) { | |
| $subject = 'Post Published: ' . $post->post_title . ''; | |
| if(get_field('temp_group_leader') && get_field('temp_leader')) { | |
| $message = 'Hi ' . get_the_author_meta('first_name', $temp_id) . ', Looks like ' . get_the_author_meta('first_name', $author_id) . ' ' . $author_last = get_the_author_meta('last_name', $author_id) . ' just published a new post: ' . get_permalink($post_id) . '.'; | |
| wp_mail(get_the_author_meta('user_email', $temp_id), $subject, $message); | |
| } else { | |
| $message = 'Hi ' . get_the_author_meta('first_name', $leader_id) . ', Looks like ' . $author_name . ' ' . $author_last . ' just published a new post: ' . get_permalink($post_id) . '.'; | |
| wp_mail(get_the_author_meta('user_email', $leader_id), $subject, $message); | |
| } | |
| } | |
| endwhile; | |
| endif; | |
| endwhile; | |
| wp_reset_query(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment