我想知道更改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
?
答案 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
希望这会有所帮助。 感谢