wordpress更改帖子的最后修改日期到发布日期(预定发布)

时间:2014-12-05 03:52:55

标签: mysql wordpress plugins modified-date

我想知道更改post_modified的值,因此该值与post_date具有相同的值。

但是Wordpress有一个修订系统,所以我想更改修订版的post_modified以使post_date具有相同的值。

以下是我要更改的问题:

$query = "UPDATE $wpdb->posts 
          SET 
              post_modified = '$recent->post_date',
              post_modified_gmt = '$recent->post_date_gmt'
          WHERE 
              ID = '$update->ID'";

$wpdb->query($query);


$recent->post_date is the post_date (scheduled time / time where our post will appear in the website)

$recent->post_date_gmt is post_date_gmt

$update->ID是posts表中的修订ID。

但是当我运行查询时,它不会更改值并停止我的插件。

我错过了什么吗?或者是Wordpress本身不允许我们更改post_modified

2 个答案:

答案 0 :(得分:2)

您可以使用普通的wp_update_post函数

    $args = new stdClass;
    $args->ID = $yourPostIdVal;
    $args->post_modified = $yourDateString;
    $args->post_modified_gmt = $yourGmDateString;
    wp_update_post($args);

答案 1 :(得分:0)

当我尝试更新post_date时,我遇到了类似这个问题。最后我用“`”标记来包装列名。完全如下。

$postID = $update->ID;
$datetime = date("Y-m-d H:i:s");   



$wpdb->query( "UPDATE `$wpdb->posts` SET 
                                    `post_date` = '".$datetime."'
                                    WHERE `ID` = '".$postID."'" );

请记住,$ datetime是一个有效的日期,如2015-01-04或2015-01-04 23:59:59

希望这会有所帮助。 感谢