С ключом 'comment_post_ID'
, где будет показан ваш комментарий, поэтому желаемый идентификатор продукта
Затем вы можете использовать update_comment_meta()
выделенную функцию WordPress для добавления рейтинга, например:
update_comment_meta( $comment_id, 'rating', 3 ); // The rating is an integer from 1 to 5
Таким образом, ваш код будет выглядеть как (где $product_id
- идентификатор целевого продукта для этого обзора):
$comment_id = wp_insert_comment( array(
'comment_post_ID' => 37, // <=== The product ID where the review will show up
'comment_author' => 'LoicTheAztec',
'comment_author_email' => 'loictheaztec@fantastic.com', // <== Important
'comment_author_url' => '',
'comment_content' => 'content here',
'comment_type' => '',
'comment_parent' => 0,
'user_id' => 5, // <== Important
'comment_author_IP' => '',
'comment_agent' => '',
'comment_date' => date('Y-m-d H:i:s'),
'comment_approved' => 1,
) );
// HERE inserting the rating (an integer from 1 to 5)
update_comment_meta( $comment_id, 'rating', 3 );
Проверено и работает как задумано.
Письмо автора и идентификатор пользователя должны быть некоторыми из существующих.