Unfortunately, no success after a test 🙁
I put the follwing:
if ( get_post_status( $post_id ) === 'publish' ) {
$post_title = apply_filters('the_title', get_post_field('post_title', $post_id));
$post_content = apply_filters('the_content', get_post_field('post_content', $post_id));
$taxonomy = "category";
$args = array('orderby' => 'name', 'order' => 'ASC');
$cat = wp_get_post_terms( $post_id, $taxonomy, $args );
$categorie = $cat[0]->name;
I get the count of cat in the wp_mail in the body output – the count is at 0.
Interestingly – when I change the taxonomy to Category (big C) – I get an array with an error. (Count 1 in the mail body)
I have written a test function that I do not run in save_post hook but by my own call – in this function, wp_get_post_terms works with the same post ID without errors.
An important note yet:
In the save_post function is a check – I compare get_post_time (Unix timetamp) with get_modified_time (Unix timestamp)
If this comparison shows a difference – is it a later update of the post – is the difference 0 is it a new post.
When I create a new post category does not work.
When I update the post the function works for the category
Any other approaches that might help?
(I also like to post the whole class here, if necessary)