我制作了这个动作挂钩,每当自定义帖子类型“events”中有新帖子时,它都会向用户发送一封电子邮件。
function email_members($post_id) {
global $wpdb;
$usersarray = $wpdb->get_col("SELECT user_email FROM wp_users");
$users = implode(",", $usersarray);
if( ( $_POST[\'post_status\'] == \'publish\' ) && ( $_POST[\'original_post_status\'] != \'publish\' ) ) {
$subject = \'Event Reminder\';
$post_url = get_permalink($post_id);
$post_title = get_the_title($post_id);
$event_date = get_post_meta( $post_id, \'ch_event_date\', true );
$message = "APAC Ministries Event Reminder for: ".$post_title."\\n\\n";
$message .= "Date: ".$event_date;
wp_mail($users, $subject, $message );
}
}
add_action(\'publish_th_events\', \'email_members\');
但是
$event_date
它总是空的。我尝试在另一个文件中运行此代码,效果良好:
global $post;
$test = get_post_meta($post->ID, \'ch_event_date\', true);
echo $test;
我似乎无法在wp\\u邮件中使用get\\u post\\u meta。
欢迎任何替代解决方案。谢谢