Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Wordpress中以编程方式更改发布日期(添加x天)?更改函数中的批量发布日期_Php_Mysql_Wordpress - Fatal编程技术网

Php 如何在Wordpress中以编程方式更改发布日期(添加x天)?更改函数中的批量发布日期

Php 如何在Wordpress中以编程方式更改发布日期(添加x天)?更改函数中的批量发布日期,php,mysql,wordpress,Php,Mysql,Wordpress,在接下来的5个月里,我有数千个帖子;每天发布500篇文章。希望通过每天发布125篇文章将其推广到未来20个月 因此,我们可能需要运行一个db查询,并在接下来的5个月内获得所有安排的帖子。然后,对于每一个特定的日期,我们需要在125篇文章中增加150天,在接下来的125篇文章中增加300天,在接下来的125篇文章中增加450天,只需将最后的125篇文章留到未来5个月内发表即可 需要以编程方式执行,因为在phmyadmin中手动执行会花费很长时间 我对$wpdb类和php不够熟悉;非常感谢您的帮助!

在接下来的5个月里,我有数千个帖子;每天发布500篇文章。希望通过每天发布125篇文章将其推广到未来20个月

因此,我们可能需要运行一个db查询,并在接下来的5个月内获得所有安排的帖子。然后,对于每一个特定的日期,我们需要在125篇文章中增加150天,在接下来的125篇文章中增加300天,在接下来的125篇文章中增加450天,只需将最后的125篇文章留到未来5个月内发表即可

需要以编程方式执行,因为在phmyadmin中手动执行会花费很长时间


我对$wpdb类和php不够熟悉;非常感谢您的帮助!谢谢。

以下是我如何解决这个问题的。由于只需5个月,请编写以下代码并运行5次:

$i = 1;
while ($i < 30) {

    //Adding '0' to the dates lower than 10 to make them look like how it's saved in DB; 2018-12-01 00:00:00
    $i_string = $i;
    if ($i < 10) {
        $i_string = '0'.$i;
    }

    global $wpdb;

    //Updating 125 post date per each date from September to the corresponding date in January, June and November 2019
    for ($j = 1; $j < 12; $j+5) {
        $wpdb->query( $wpdb->prepare(
            "UPDATE wp_posts 
            SET post_date='2019-0$j-$i_string 00:00:00', post_date_gmt='2019-0$j-$i_string 08:00:00' 
            WHERE post_date = '2018-09-$i_string 00:00:00' 
            AND post_type = 'post' 
            LIMIT 125;"
        ));
    }

    $i++;
}   
$i=1;
而($i<30){
//将“0”添加到小于10的日期,使其看起来像是在DB中保存的;2018-12-01 00:00:00
$i_string=$i;
如果($i<10){
$i_字符串='0'。$i;
}
全球$wpdb;
//从2019年9月至2019年1月、6月和11月的相应日期,每个日期更新125个发布日期
对于($j=1;$j<12;$j+5){
$wpdb->query($wpdb->prepare)(
“更新wp_帖子
设置post_date='2019-0$j-$i_string 00:00:00',post_date='2019-0$j-$i_string 08:00:00'
其中post_日期='2018-09-$i_字符串00:00:00'
和post_type='post'
限制125;”
));
}
$i++;
}   

我只用了几分钟就运行了5次,得到了我想要的。但我不会接受我的解决方案,因为它不适用于可能需要更改好几个月的日期的人

即使你想让别人为你写这篇文章,但这并不是这么做的目的。你没有提供足够的信息。在这里,我们帮你修复代码,我们不为你写所有的东西,没有提供更多的信息,比如预定帖子的确切开始日期和结束日期,因为我不希望有人为我写整个代码,只是复制和粘贴!这不是目的;不过谢谢你。在你提出问题的时候要考虑一下。。,