Created
April 27, 2015 07:45
-
-
Save garciasanchezdani/a3220b97fec6ac61d5cb to your computer and use it in GitHub Desktop.
Script which insert comments to a post of wordpress - by using the plugin rich reviews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addComment(){ | |
global $wpdb; | |
$slug = 'YOUR_SLUG'; //the slug of your post where you want to insert comments | |
$post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$slug'"); //retrieve id of the post | |
$comentarios = array(); //custom array of comments to insert...please fill in with your values | |
$nombres = array(); //custom array of names to insert...please fill in with your values | |
$randIP = "".mt_rand(0,255).".".mt_rand(0,255).".".mt_rand(0,255).".".mt_rand(0,255); //random ip | |
//one comment | |
$comentario_aleatorio = $comentarios[array_rand($comentarios)]; //get a random value of the comments array | |
$nombre_aleatorio = $nombres[array_rand($nombres)]; //get a random value of the names array | |
//insert in the table | |
$table = 'wp_richreviews'; | |
$data = array( date_time => current_time( 'mysql' ),reviewer_name => $nombre_aleatorio, reviewer_email => "", review_title => "", review_rating => rand(3,5), | |
review_text => $comentario_aleatorio, review_status => 1, reviewer_ip => $randIP, post_id => $post_id, review_category => "none" ); | |
$wpdb->insert( $table, $data ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment