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
       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!

1 Answer 1



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.

  • But I was able to get the tags with your code also :)
    – BlueSuiter
    Apr 7, 2020 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.