WordPress获取指定ID评论数据函数:get_comment

WordPress函数get_comment用于获取指定ID的评论对象数据。

get_comment( WP_Comment|string|int $comment = null, string $output = OBJECT ): WP_Comment|array|null

函数参数

$comment

WP_Comment|字符串|整数

评论对象或评论ID。

$output

字符串

返回的类型,OBJECT, ARRAY_A或ARRAY_N

函数返回值

get_comment()函数返回指定评论对象数据。

WP_Comment Object
(
    [comment_ID] => 6
    [comment_post_ID] => 241
    [comment_author] => admin
    [comment_author_email] => beizigen@qq.com
    [comment_author_url] => 
    [comment_author_IP] => 127.0.0.1
    [comment_date] => 2024-04-08 11:57:36
    [comment_date_gmt] => 2024-04-08 03:57:36
    [comment_content] => 评论内容
    [comment_karma] => 0
    [comment_approved] => 1
    [comment_agent] => Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0
    [comment_type] => comment
    [comment_parent] => 0
    [user_id] => 1
    [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] => pinged
            [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
        )

)

函数使用示例

<?php
$comment_id = 6;
$comments = get_comment($comment_id); 
$comment_content = $comments->comment_content;
?>

扩展阅读

get_comment()函数位于:wp-includes/comment.php

相关函数:

Typora