我有一个职位计划从现在起一周后出去。我今天改变了计划,顺其自然。
最终发布时,发布日期是计划发布的日期。但修改日期仍然提前了一周!
我该如何做才能使预定的帖子一发布,就将修改日期更新为帖子日期?
我有一个职位计划从现在起一周后出去。我今天改变了计划,顺其自然。
最终发布时,发布日期是计划发布的日期。但修改日期仍然提前了一周!
我该如何做才能使预定的帖子一发布,就将修改日期更新为帖子日期?
在其他人的帮助下,我设法解决了这个问题。
将此添加到您的函数中。php:
// Scheduled posts should update modified date when published
function update_modified_date_to_post_date( $post ) {
$updated_data = [
\'ID\' => $post->ID,
\'post_modified\' => $post->post_date,
\'post_modified_gmt\' => $post->post_date_gmt
];
wp_update_post( $updated_data );
}
add_action( \'future_to_publish\', \'update_modified_date_to_post_date\', 10, 1 );
wp_update_post
实际将当前时间设置为post_modified
和post_modified_gmt
每次都被调用。
您可以使用$wpdb
查询以使其实际工作。
function update_modified_date_to_post_date( $post ) {
global $wpdb;
$wpdb->query("UPDATE $wpdb->posts SET post_modified = \'{$post->post_date}\', post_modified_gmt = \'{$post->post_date_gmt}\' WHERE ID = {$post->ID}" );
}
add_action( \'future_to_publish\', \'update_modified_date_to_post_date\', 10, 1 );
我有一个自定义的帖子类型,我想在我的网站上的分类页面上完全显示该帖子类型,而不是网站的常规博客部分。我制作了一个自定义分类法和帖子类型,如下所示:add_action(\'init\', \'create_post_types\'); function create_post_types() { register_taxonomy(\'tips-and-tricks-taxonomy\', \'tat\', array( \'hierarchical\'