WordPress add_comment_meta + comment_meta正确用法?

问题描述 投票:0回答:1

我的WP functions.php文件上有一个非常简单的PHP代码,它创建了一个新注释:

    $time = current_time('mysql');

    $com_meta = array(
        "img_id" => $attach_id,
    );
    // $attach_id holds the ID of an image I want to attach to the comment in comment_meta

    $data = array(
        'comment_post_ID'        => 2819,
        'comment_author'         => 'My test title',
        'comment_author_email'   => '[email protected]',
        'comment_content'        => 'Test comment message.',
        'comment_type'           => '',
        'comment_date'           => $time,
        'comment_approved'       => 0,
        'comment_meta'           => $com_meta,
    );

    $comm_id = wp_insert_comment( $data );

    die( 'comment created, comment id: ' . $comm_id );

没有PHP错误,并且注释创建就很好。像“我的测试标题”这样的所有其他数据都按预期存在。只有comment_meta字段完全丢失。在$ comment对象中,甚至没有空的comment_meta。

我可能会缺少什么?

这是$ comment对象的外观:

WP_Comment对象([comment_ID] => 9 [comment_post_ID] => 2819 [comment_author] =>我的测试标题[comment_author_email] => [email protected] [comment_author_url] => [comment_author_IP] => [comment_date] => 2019-10-18 13:33:03 [comment_date_gmt] => 2019-10-18 10:33:03 [comment_content] =>测试评论消息[comment_karma] => 0 [comment_approved] => 0 [comment_agent] = > [comment_type] => [comment_parent] => 0 [user_id] => 0 [children:protected] => [populated_children:protected] => [post_fields:protected] => Array([0] => post_author [1] => post_date [2] => post_date_gmt [3] => post_content [4] => post_title [5] => post_excerpt [6] => post_status [7] => comment_status [8] => ping_status [9] => post_name [10] => to_ping [11] => ping [12] => post_modified [13] => post_modified_gmt [14] => post_content_filtered [15] => post_parent [16] => guid [17] => menu_order [ 18] => post_type [19] => post_mime_type [20] => comment_count)))>

我在WP functions.php文件中有一个非常简单的PHP代码,它创建了一个新注释:$ time = current_time('mysql'); $ com_meta = array(“ img_id” => $ attach_id,); ...

arrays wordpress arguments comments
1个回答
0
投票

我找到了答案。

© www.soinside.com 2019 - 2024. All rights reserved.