posts - Update all comments time to random dates?

I found this code snippet which randomly changes all the dates for all posts.(Original Post : Update existing post dat

I found this code snippet which randomly changes all the dates for all posts. (Original Post : 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 );
  }
}

I tried editing it & changing the function to fetch comments & edit them for my woocommerce reviews / comments but it doesn't seem to work? Any tweak that would help?

Thanks

I found this code snippet which randomly changes all the dates for all posts. (Original Post : 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 );
  }
}

I tried editing it & changing the function to fetch comments & edit them for my woocommerce reviews / comments but it doesn't seem to work? Any tweak that would help?

Thanks

Share Improve this question edited Dec 12, 2019 at 6:41 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 12, 2019 at 3:40 katypkatyp 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

You want Virtual Reviews. Actually you can call it fake reviews. Or just you want to change your existing reviews date? If you want fake reviews for your woocommerce then you can use this plugin. WooCommerce Virtual Review Plugin

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744913895a4600716.html

相关推荐

  • posts - Update all comments time to random dates?

    I found this code snippet which randomly changes all the dates for all posts.(Original Post : Update existing post dat

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信