0

I am trying to insert comment in WordPress using PHP, But it's not print ID when executing it. When I remove the symbol from comments it will work correctly. Need solution

$content = 'hello ';
$agent = $_SERVER['HTTP_USER_AGENT'];
$data = array(
    'comment_post_ID' => 1,
    'comment_author' => 'admin',
    'comment_author_email' => "admin@gmail.com",
    'comment_content' => $content,
    'comment_agent' => $agent,
    'comment_date' => '2022-02-02 10:10:10',
    'comment_approved' => 1,
);

$comment_id = wp_insert_comment($data);
echo $comment_id;
RIZI
  • 104
  • 1
  • 7
  • `var_dump(wp_insert_comment($data))` is false? What is charset of table/columns, and driver? – user3783243 Aug 30 '22 at 17:56
  • @user3783243 yes its bool(false), and charset is utf8 – RIZI Aug 30 '22 at 18:07
  • 2
    utf8 is not compatible with that. MySQL utf8 charset doesnt include emojis. See https://stackoverflow.com/questions/39463134/how-to-store-emoji-character-in-mysql-database That is my presumption, I don't know how to make wordpress return the relevant error.. but you should look into that as well – user3783243 Aug 30 '22 at 18:28

0 Answers0