是否将所有评论时间更新为随机日期?

时间:2019-12-12 作者:katyp

我发现这个代码片段随机更改了所有帖子的所有日期。(原职务:Update existing post dates to random dates )

<?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 );
  }
}
我试着编辑它&;更改函数以获取注释(&A);为我的woocommerce评论/评论编辑它们,但它似乎不起作用?有什么好办法吗?

谢谢

1 个回复
SO网友:Hasan Uj Jaman

您需要虚拟评论。实际上,你可以称之为虚假评论。或者只是想更改现有的评论日期?如果你想为你的woocommerce提供虚假评论,那么你可以使用这个插件。WooCommerce Virtual Review Plugin