我创建了一个插件,通过wp\\u mail()将昨天和今天的列表帖子发送给WordPress multisite的成员,并在localhost上成功发送了列表帖子。
但在live server上,上个月发布的结果显示混合,去年发布的结果。密码
function test_plugin() {
$blogs = get_last_updated(\' \', 0, 40);
global $wpdb;
//find today post from WordPress network
foreach ($blogs AS $blog) {
switch_to_blog($blog["blog_id"]);
$today = getdate();
$yesterday = date(\'F jS, Y\',strtotime("-1 days"));
$yesterday_today = array(
\'order\' => \'ASC\',
\'orderby\' => \'date\',
\'date_query\' => array(
array(
\'after\' => $yesterday, //\'January 1st, 2013\',
\'before\' => array(
\'year\' => date(\'Y\'),
\'month\' => date(\'n\'),
\'day\' => date(\'j\'),
),
\'inclusive\' => true,
),
),
\'posts_per_page\' => -1,
);
$wpb_all_query = new WP_Query($yesterday_today); ?>
<?php if ( $wpb_all_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post();
$result = get_the_date(\'Y-m-d\')." | ".get_bloginfo()." | ".\'<a href="\'.get_permalink().\'?utm_source=newsletter&utm_medium=email&utm_campaign=budayasaya\'.\'">\'.get_the_title()."</a><br>";
$content[]=$result;
?>
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php restore_current_blog(); ?>
<?php
}
//save result as one variable
$list_post = implode(" ", $content);
//Check if any post, sent it
if ($list_post != NULL) {
echo "This will sent email to users with content: <br>".$list_post;
$subject = \'Daily News\';
$headers = array(\'Content-Type: text/html; charset=UTF-8\');
//sent email to multiple recipients
$get_email = $wpdb->get_results("SELECT email FROM penerima WHERE status = \'1\'");
foreach ( $get_email as $recipients ) {
$to = $recipients->email;
wp_mail( $to, $subject, $list_post, $headers );
}
}
}
我的git
https://github.com/ahmadbagwi/testemailblast/blob/master/index.php
SO网友:D. Dan
你能尝试使用另一种日期格式吗?示例:
foreach ($blogs AS $blog) {
switch_to_blog($blog["blog_id"]);
$yesterday_today = array(
\'order\' => \'ASC\',
\'orderby\' => \'date\',
\'date_query\' => array(
array(
\'after\' => array(
\'year\' => date(\'Y\',strtotime("-1 days")),
\'month\' => date(\'n\',strtotime("-1 days")),
\'day\' => date(\'j\',strtotime("-1 days")),
),
\'before\' => array(
\'year\' => date(\'Y\'),
\'month\' => date(\'n\'),
\'day\' => date(\'j\'),
),
\'inclusive\' => true,
),
),
\'posts_per_page\' => -1,
);
//....