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!
1 Answer
Reset to default 0wordpress.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.