我正在尝试从数据库手动编写产品注释。
$wpdb->insert($table,
array(
"comment_post_ID" => '26475',
"comment_author" => 'text',
"comment_author_email" => "text@text",
"comment_author_IP" => "192.168.122.122",
"comment_date" => "2017-09-28 14:53:46",
"comment_date_gmt" => "2017-09-28 10:53:46",
"comment_content" => "Testing Product",
"comment_karma" => "0",
"comment_approved" => "1",
"comment_agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36",
"comment_parent" => "0",
"user_id" => "0",
));
$ListingID = $wpdb->get_var("SELECT comment_ID FROM ". $table ." WHERE comment_post_ID = '26475' AND comment_content = 'Very Good Product'");
$wpdb->insert($table_comment_meta,
array(
"comment_id" => $ListingID,
"meta_key" => "verified",
"meta_value" => "0",
));
// $wpdb->insert($table_comment_meta,
array(
"comment_id" => $ListingID,
"meta_key" => "rating",
"meta_value" => "5",
));
在我运行代码并转到产品页面后,会显示评论和评分,但是我有问题,在显示评论之前会对其进行计数,它会计算此评论。< / p>
有人知道我在这里缺少什么。
答案 0 :(得分:0)
你可以试试这个
<?php
$time = current_time('mysql');
$data = array(
'comment_post_ID' => 1,
'comment_author' => 'admin',
'comment_author_email' => 'admin@admin.com',
'comment_author_url' => 'http://',
'comment_content' => 'content here',
'comment_type' => '',
'comment_parent' => 0,
'user_id' => 1,
'comment_author_IP' => '127.0.0.1',
'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
'comment_date' => $time,
'comment_approved' => 1,
);
wp_insert_comment($data);
?>
希望这会有所帮助。