百度
360搜索
搜狗搜索

wordpress自动将新帖子的发布时间设置为早上 8 点详细介绍

请改用不同的钩子,它将同时适用于创建和更新事件:
function set_default_post_time_to_8am_after_publish( $post_id, $post, $update ) {
// Check if the post is new (not updated) and is of type "draft" or "auto-draft"
if ( $update || $post->post_status !== 'draft' ) {
return;
}

// Check if the post has already been processed
if ( get_post_meta( $post_id, '_set_8am_time', true ) ) {
return;
}

// Set the post date to 8:00 AM
$current_date = substr( $post->post_date, 0, 10 ); // Get only the date (YYYY-MM-DD)
$new_post_date = $current_date . ' 08:00:00';
$new_post_date_gmt = get_gmt_from_date( $new_post_date ); // Adjust GMT time

// Update the values in the database
global $wpdb;
$wpdb->update(
$wpdb->posts,
array(
'post_date' => $new_post_date,
'post_date_gmt' => $new_post_date_gmt,
),
array( 'ID' => $post_id )
);

// Add a meta field to indicate that the post has been processed
update_post_meta( $post_id, '_set_8am_time', true );
}
add_action( 'wp_after_insert_post', 'set_default_post_time_to_8am_after_publish', 10, 3 );

阅读更多 >>>  update set from where,update 表A set A.字段=(selec 字段 FROM 表B) from 表A,表B where A.主键=B.主键 提示命令未正确结束

网站数据信息

"wordpress自动将新帖子的发布时间设置为早上 8 点"浏览人数已经达到21次,如你需要查询该站的相关权重信息,可以点击进入"Chinaz数据" 查询。更多网站价值评估因素如:wordpress自动将新帖子的发布时间设置为早上 8 点的访问速度、搜索引擎收录以及索引量、用户体验等。 要评估一个站的价值,最主要还是需要根据您自身的需求,如网站IP、PV、跳出率等!