在我的主题中,我想创建一个函数,当元盒值发生更改时,会通知作者。
实际上,我有一个自定义元盒,它循环遍历特定级别的用户角色(自定义用户角色),其中<option value="<the user\'s ID>"
通过使用以下代码更改作者,我可以做到这一点:
function check_values($post_ID, $post_after, $post_before){
if( $post_after->post_author !== $post_before->post_author ) {
$author = $post_after->post_author; /* Post author ID. */
$name = get_the_author_meta( \'display_name\', $author );
$email = get_the_author_meta( \'user_email\', $author );
$title = $post_after->post_title;
$permalink = get_permalink( $ID );
$edit = get_edit_post_link( $ID, \'\' );
$to[] = sprintf( \'%s <%s>\', $name, $email );
$subject = sprintf( \'Published: %s\', $title );
$message = sprintf (\'Congratulations, %s! Your article “%s” has been published.\' . "\\n\\n", $name, $title );
$message .= sprintf( \'View: %s\', $permalink );
$headers[] = \'\';
wp_mail( $to, $subject, $message, $headers );
}
}
add_action( \'post_updated\', \'check_values\', 10, 3 );
我尝试添加
get_post_meta( get_the_ID(), \'key_1\', true );
但在抄本中查找
post_updated
我不知道是否可以打电话
$post_before->$meta_key
或
$post_after->$meta_key
有没有办法做到这一点?还是纯粹为了内在价值?