嗨大家我对wordpress非常陌生并且正在学习,下面的代码结果是,我尝试了之后编辑了我的问题,
include('wp-load.php');
// FOR GET_USERDATA FUNCTION & $WPDB
include('wp-includes/pluggable.php');
// include(' wp-includes / author-template.php');
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
require_once ('wp-content/themes/directoryengine/includes/places.php');
// $count = convert_place($post_ID);
>
<?php
function sendMail() {
$authors=get_users();
$i=0;
//get all users list
foreach($authors as $author){
$authorList[$i]['id']=$author->data->ID;
$authorList[$i]['name']=$author->data->display_name;
$authorList[$i]['user_email']=$author->data->user_email;
$i++;
}
$to = array();
foreach($authorList as $author){
$args=array(
'post_type'=> 'place',
'author'=>$author['id']
// 'caller_get_posts'=>1
);
$email = $author['user_email'];
$query = new WP_Query($args);
$count_key = 'view_count';
//Returns values of the custom field with the specified key from the specified post.
$count = get_post_meta($post_ID, $count_key, true);
if($query->have_posts() ) {
echo $email.'<br>';
while($query->have_posts()){
$query->the_post();
$post_ID = get_the_ID();
$view_count = get_post_meta($post_ID, 'view_count', true );
//the_title();
if($view_count==null){
$view_count = 0;
}
$pauthor = $author['name'];
$ptitle = get_the_title($post_ID);
$from_email = "****@gmail.com";
$headers = "From:".$from_email;
$body = '';
$body.= 'Dear '. $author['name'].'\r\n';
$body.= 'This is to notify you of your place view count below: \r\n';
$body.= get_the_title($post_ID).' :<b> '.$view_count.'</b>\r\n' ;
$body.= 'From: Admin';
echo $body.'<br>';
}
wp_reset_postdata();
}
}
echo $body;
}
echo sendMail();
?>
我想向每个用户发送$ body,因此如果用户有多个帖子,则会通过一封电子邮件将其发送给各自的用户。