本地和服务器上的查询结果不同

时间:2018-09-10 作者:ahmadbagwi

我创建了一个插件,通过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 ); 
    }
}
}
我的githttps://github.com/ahmadbagwi/testemailblast/blob/master/index.php

1 个回复
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,
    );
    //....

结束

相关推荐

如何将现有的子域连接到新的WordPress MultiSite?

我们正在开发一个WordPress多站点(由5个子网站组成),我们面临着这个问题。我们将multisite开发为http://wpsite.com/sub1, http://wpsite.com/sub2,... 等等。现在我们想以sub1访问这些站点。主站点。com,sub2。主站点。com和主站点。com已经是一个独立的网站。我们检查了许多文章和问题,但没有找到合适的解决方案。我们已尝试从sub1执行永久重定向。主站点。指向的comhttp://wpsite.com/sub1, 然而,地址栏中的URL