get_the_tags doesn’t works?

Question

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!

0
Nadia 3 years 2020-04-06T08:51:03-05:00 0 Answers 93 views 0

Leave an answer

Browse
Browse