Set Post Category Not Working
-
Hi,
I have a little issue sending mails after a post was published. It looks like WP is always putting my new post in the default category first and than in the selected one.
Here is my setup and what I want to do:
Different user roles should get notifications depending on the selected post category. I wanted to use “Buddypress” in combination with “Publish Press” but never got it to work, so I built a debugging function:function on_all_status_transitions($ID, $post ) { $author = $post->post_author; /* Post author ID. */ $name = get_the_author_meta( 'display_name', $author ); $email = 'mail'; $title = $post->post_title; $permalink = get_permalink( $ID ); $edit = get_edit_post_link( $ID, '' ); $to[] = sprintf( '%s <%s>', $name, $email ); $category = get_the_category($post->ID); $subject = sprintf( 'Published: %s', $title ); $message .= $category[0]->name; $headers[] = ''; wp_mail( $to, $subject, $message, $headers ); } add_action( 'publish_post', 'on_all_status_transitions', 10, 2 );
After publishing a new post, I always get 2 Mails. The first one for the default category and a few seconds later one mail with the right category. Because I want to use an if statement based on the category, it never works because I always get the default category sent to my function…
Here’s a Screenshot
Can anyone maybe help me with that?
Thanks in advance,
Pascal
- The topic ‘Set Post Category Not Working’ is closed to new replies.