我想把我已经发布的帖子的发布日期改为从2015年到今天的随机日期。
如何使用代码在WordPress中执行此操作。
我想把我已经发布的帖子的发布日期改为从2015年到今天的随机日期。
如何使用代码在WordPress中执行此操作。
<?php
/**
* Plugin Name: WPSE 259750 Random Dates
* Description: On activation, change the dates of all posts to random dates
*/
//* We want to do this only once, so add hook to plugin activation
register_activation_hook( __FILE__ , \'wpse_259750_activation\' );
function wpse_259750_activation() {
//* Get all the posts
$posts = get_posts( array( \'numberposts\' => -1, \'post_status\' => \'any\' ) );
foreach( $posts as $post ) {
//* Generate a random date between January 1st, 2015 and now
$random_date = mt_rand( strtotime( \'1 January 2015\' ), time() );
$date_format = \'Y-m-d H:i:s\';
//* Format the date that WordPress likes
$post_date = date( $date_format, $random_date );
//* We only want to update the post date
$update = array(
\'ID\' => $post->ID,
\'post_date\' => $post_date,
\'post_date_gmt\' => null,
);
//* Update the post
wp_update_post( $update );
}
}
运行以下代码时:update_post_meta( 1, \'_visibility\', \'visible\' ); wordpress是否检查post\\u id1 钥匙_visable 值为visible 在写入数据库之前?我有一个导入脚本,我想知道这是否可以节省处理时间。function update_post_meta_check($post_id, $key, $value) { $old = get_post_meta($post_id, $key);&