admin管理员组

文章数量:1390564

I am creating a plugin in which a user will submit their email address and favourite tags. When publishing a new post, if the post has tags similar to the user's favourite tags, an email will be sent to the user. For this I need to compare new post tags with the user's favourite tags.

On basis of its definition get_the_tags($postId) should return an array of post_tags but it doesn't. I don't know what to do!

add_action('publish_post', array( $myClass ,'wp_send_emailToUser' ), 10, 2);
class customFunction{
function wp_send_emailToUser( $postId, $post ) {
    $posttags = get_the_tags($postid);
    if ($posttags) {
       //...do sth
    }else{
       error_log( "@ tags are empty,post id={$postId}" );
    }
}

The new post I published has some tags but it goes to the else part and print error_log("@ tags are empty, post id={$postId}"); in my debug.log file. I searched a lot but didn't find anything!

I am creating a plugin in which a user will submit their email address and favourite tags. When publishing a new post, if the post has tags similar to the user's favourite tags, an email will be sent to the user. For this I need to compare new post tags with the user's favourite tags.

On basis of its definition get_the_tags($postId) should return an array of post_tags but it doesn't. I don't know what to do!

add_action('publish_post', array( $myClass ,'wp_send_emailToUser' ), 10, 2);
class customFunction{
function wp_send_emailToUser( $postId, $post ) {
    $posttags = get_the_tags($postid);
    if ($posttags) {
       //...do sth
    }else{
       error_log( "@ tags are empty,post id={$postId}" );
    }
}

The new post I published has some tags but it goes to the else part and print error_log("@ tags are empty, post id={$postId}"); in my debug.log file. I searched a lot but didn't find anything!

Share Improve this question edited Apr 6, 2020 at 11:39 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Apr 6, 2020 at 10:07 NadiaNadia 351 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

wordpress.stackexchange/questions/266999

I found the problem in the above link , I should use set_object_terms becaus tags will not be with the post in publish_post.

本文标签: plugin developmentgetthetags doesn39t works