{"id":5556,"date":"2026-02-12T20:44:46","date_gmt":"2026-02-13T01:44:46","guid":{"rendered":"https:\/\/chubes.net\/?documentation=wp_comment_query"},"modified":"2026-03-13T03:28:05","modified_gmt":"2026-03-13T07:28:05","slug":"wp_comment_query","status":"publish","type":"documentation","link":"https:\/\/chubes.net\/docs\/wordpress-core\/comments\/wp_comment_query\/","title":{"rendered":"WP_Comment_Query"},"content":{"rendered":"<p>Core class for querying comments from the database.<\/p><p><strong>Since:<\/strong> 3.1.0<br \/>\n<strong>Source:<\/strong> <code>wp-includes\/class-wp-comment-query.php<\/code><\/p><h2 class=\"wp-block-heading\">Overview<\/h2><p><code>WP_Comment_Query<\/code> retrieves comments based on specified criteria. It supports filtering, pagination, meta queries, date queries, and hierarchical comment retrieval.<\/p><h2 class=\"wp-block-heading\">Basic Usage<\/h2><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Simple query\n$query = new WP_Comment_Query( array(\n    &#039;post_id&#039; =&gt; 42,\n    &#039;status&#039;  =&gt; &#039;approve&#039;,\n) );\n$comments = $query-&gt;comments;\n\n\/\/ Using get_comments() wrapper\n$comments = get_comments( array(\n    &#039;post_id&#039; =&gt; 42,\n    &#039;status&#039;  =&gt; &#039;approve&#039;,\n) );<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Class Properties<\/h2><figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$request<\/code><\/td><td>string<\/td><td>The SQL query string<\/td><\/tr><tr><td><code>$meta_query<\/code><\/td><td>WP_Meta_Query<\/td><td>Meta query instance<\/td><\/tr><tr><td><code>$date_query<\/code><\/td><td>WP_Date_Query<\/td><td>Date query instance<\/td><\/tr><tr><td><code>$query_vars<\/code><\/td><td>array<\/td><td>Query variables set by user<\/td><\/tr><tr><td><code>$query_var_defaults<\/code><\/td><td>array<\/td><td>Default values for query vars<\/td><\/tr><tr><td><code>$comments<\/code><\/td><td>int[]<\/td><td>WP_Comment[]<\/td><\/tr><tr><td><code>$found_comments<\/code><\/td><td>int<\/td><td>Total found comments<\/td><\/tr><tr><td><code>$max_num_pages<\/code><\/td><td>int<\/td><td>Number of pages<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">Query Variables<\/h2><h3 class=\"wp-block-heading\">Comment Selection<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>comment__in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Include specific comment IDs<\/td><\/tr><tr><td><code>comment__not_in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Exclude specific comment IDs<\/td><\/tr><tr><td><code>parent<\/code><\/td><td>int<\/td><td>&#8221;<\/td><td>Parent comment ID<\/td><\/tr><tr><td><code>parent__in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Parent IDs to include children for<\/td><\/tr><tr><td><code>parent__not_in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Parent IDs to exclude children for<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Get specific comments\n$comments = get_comments( array(\n    &#039;comment__in&#039; =&gt; array( 10, 20, 30 ),\n) );\n\n\/\/ Get replies to specific comment\n$replies = get_comments( array(\n    &#039;parent&#039; =&gt; 123,\n) );\n\n\/\/ Get replies to multiple parents\n$replies = get_comments( array(\n    &#039;parent__in&#039; =&gt; array( 10, 20, 30 ),\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Post Filtering<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>post_id<\/code><\/td><td>int<\/td><td>0<\/td><td>Limit to specific post ID<\/td><\/tr><tr><td><code>post__in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Include comments from these posts<\/td><\/tr><tr><td><code>post__not_in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Exclude comments from these posts<\/td><\/tr><tr><td><code>post_author<\/code><\/td><td>int<\/td><td>&#8221;<\/td><td>Post author ID<\/td><\/tr><tr><td><code>post_author__in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Post author IDs to include<\/td><\/tr><tr><td><code>post_author__not_in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Post author IDs to exclude<\/td><\/tr><tr><td><code>post_status<\/code><\/td><td>string<\/td><td>string[]<\/td><td>&#8221;<\/td><\/tr><tr><td><code>post_type<\/code><\/td><td>string<\/td><td>string[]<\/td><td>&#8221;<\/td><\/tr><tr><td><code>post_name<\/code><\/td><td>string<\/td><td>&#8221;<\/td><td>Post slug<\/td><\/tr><tr><td><code>post_parent<\/code><\/td><td>int<\/td><td>&#8221;<\/td><td>Post parent ID<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Comments on specific post\n$comments = get_comments( array(\n    &#039;post_id&#039; =&gt; 42,\n) );\n\n\/\/ Comments on posts by author\n$comments = get_comments( array(\n    &#039;post_author&#039; =&gt; 5,\n) );\n\n\/\/ Comments on published posts only\n$comments = get_comments( array(\n    &#039;post_status&#039; =&gt; &#039;publish&#039;,\n) );\n\n\/\/ Comments on specific post type\n$comments = get_comments( array(\n    &#039;post_type&#039; =&gt; &#039;product&#039;,\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Author Filtering<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>author_email<\/code><\/td><td>string<\/td><td>&#8221;<\/td><td>Comment author email<\/td><\/tr><tr><td><code>author_url<\/code><\/td><td>string<\/td><td>&#8221;<\/td><td>Comment author URL<\/td><\/tr><tr><td><code>author__in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Registered user IDs to include<\/td><\/tr><tr><td><code>author__not_in<\/code><\/td><td>int[]<\/td><td>&#8221;<\/td><td>Registered user IDs to exclude<\/td><\/tr><tr><td><code>user_id<\/code><\/td><td>int<\/td><td>int[]<\/td><td>&#8221;<\/td><\/tr><tr><td><code>include_unapproved<\/code><\/td><td>array<\/td><td>&#8221;<\/td><td>IDs\/emails whose unapproved comments to include<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Comments by email\n$comments = get_comments( array(\n    &#039;author_email&#039; =&gt; &#039;user@example.com&#039;,\n) );\n\n\/\/ Comments by registered users\n$comments = get_comments( array(\n    &#039;author__in&#039; =&gt; array( 1, 2, 3 ),\n) );\n\n\/\/ Include unapproved comments for current user\n$comments = get_comments( array(\n    &#039;post_id&#039;            =&gt; 42,\n    &#039;include_unapproved&#039; =&gt; array( get_current_user_id() ),\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Status Filtering<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>status<\/code><\/td><td>string<\/td><td>array<\/td><td>&#8216;all&#8217;<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Status Values:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>'approve'<\/code> or <code>'1'<\/code> &#8211; Approved comments<\/li><li><code>'hold'<\/code> or <code>'0'<\/code> &#8211; Pending comments<\/li><li><code>'spam'<\/code> &#8211; Spam comments<\/li><li><code>'trash'<\/code> &#8211; Trashed comments<\/li><li><code>'all'<\/code> or <code>''<\/code> &#8211; Approved and pending (excludes spam\/trash)<\/li><li><code>'any'<\/code> &#8211; All statuses including spam\/trash<\/li><\/ul><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Approved only\n$approved = get_comments( array(\n    &#039;status&#039; =&gt; &#039;approve&#039;,\n) );\n\n\/\/ Pending moderation\n$pending = get_comments( array(\n    &#039;status&#039; =&gt; &#039;hold&#039;,\n) );\n\n\/\/ Multiple statuses\n$comments = get_comments( array(\n    &#039;status&#039; =&gt; array( &#039;approve&#039;, &#039;hold&#039; ),\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Type Filtering<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>type<\/code><\/td><td>string<\/td><td>string[]<\/td><td>&#8221;<\/td><\/tr><tr><td><code>type__in<\/code><\/td><td>string[]<\/td><td>&#8221;<\/td><td>Types to include<\/td><\/tr><tr><td><code>type__not_in<\/code><\/td><td>string[]<\/td><td>&#8221;<\/td><td>Types to exclude<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Type Values:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>'comment'<\/code> &#8211; Regular comments (includes empty type for BC)<\/li><li><code>'pingback'<\/code> &#8211; Pingback notifications<\/li><li><code>'trackback'<\/code> &#8211; Trackback notifications<\/li><li><code>'pings'<\/code> &#8211; Both pingback and trackback<\/li><li><code>'all'<\/code> or <code>''<\/code> &#8211; All types<\/li><li><code>'note'<\/code> &#8211; Internal notes (excluded by default since 6.9.0)<\/li><\/ul><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Regular comments only\n$comments = get_comments( array(\n    &#039;type&#039; =&gt; &#039;comment&#039;,\n) );\n\n\/\/ Pingbacks and trackbacks\n$pings = get_comments( array(\n    &#039;type&#039; =&gt; &#039;pings&#039;,\n) );\n\n\/\/ Exclude pingbacks\n$comments = get_comments( array(\n    &#039;type__not_in&#039; =&gt; array( &#039;pingback&#039;, &#039;trackback&#039; ),\n) );\n\n\/\/ Include notes (normally excluded)\n$notes = get_comments( array(\n    &#039;type&#039; =&gt; &#039;note&#039;,\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Ordering<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>orderby<\/code><\/td><td>string<\/td><td>array<\/td><td>&#8216;comment_date_gmt&#8217;<\/td><\/tr><tr><td><code>order<\/code><\/td><td>string<\/td><td>&#8216;DESC&#8217;<\/td><td>Order direction: &#8216;ASC&#8217; or &#8216;DESC&#8217;<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Orderby Values:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>'comment_agent'<\/code> &#8211; Browser user agent<\/li><li><code>'comment_approved'<\/code> &#8211; Approval status<\/li><li><code>'comment_author'<\/code> &#8211; Author name<\/li><li><code>'comment_author_email'<\/code> &#8211; Author email<\/li><li><code>'comment_author_IP'<\/code> &#8211; Author IP<\/li><li><code>'comment_author_url'<\/code> &#8211; Author URL<\/li><li><code>'comment_content'<\/code> &#8211; Comment content<\/li><li><code>'comment_date'<\/code> &#8211; Local date<\/li><li><code>'comment_date_gmt'<\/code> &#8211; GMT date (default)<\/li><li><code>'comment_ID'<\/code> &#8211; Comment ID<\/li><li><code>'comment_karma'<\/code> &#8211; Karma score<\/li><li><code>'comment_parent'<\/code> &#8211; Parent ID<\/li><li><code>'comment_post_ID'<\/code> &#8211; Post ID<\/li><li><code>'comment_type'<\/code> &#8211; Comment type<\/li><li><code>'user_id'<\/code> &#8211; User ID<\/li><li><code>'comment__in'<\/code> &#8211; Match order of <code>comment__in<\/code> array<\/li><li><code>'meta_value'<\/code> &#8211; Meta value (requires <code>meta_key<\/code>)<\/li><li><code>'meta_value_num'<\/code> &#8211; Numeric meta value<\/li><li><code>'none'<\/code>, <code>false<\/code>, or <code>array()<\/code> &#8211; Disable ordering<\/li><\/ul><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Oldest first\n$comments = get_comments( array(\n    &#039;orderby&#039; =&gt; &#039;comment_date&#039;,\n    &#039;order&#039;   =&gt; &#039;ASC&#039;,\n) );\n\n\/\/ By karma, then date\n$comments = get_comments( array(\n    &#039;orderby&#039; =&gt; array(\n        &#039;comment_karma&#039; =&gt; &#039;DESC&#039;,\n        &#039;comment_date&#039;  =&gt; &#039;ASC&#039;,\n    ),\n) );\n\n\/\/ By meta value\n$comments = get_comments( array(\n    &#039;meta_key&#039; =&gt; &#039;rating&#039;,\n    &#039;orderby&#039;  =&gt; &#039;meta_value_num&#039;,\n    &#039;order&#039;    =&gt; &#039;DESC&#039;,\n) );\n\n\/\/ Match specific order\n$comments = get_comments( array(\n    &#039;comment__in&#039; =&gt; array( 5, 2, 8, 1 ),\n    &#039;orderby&#039;     =&gt; &#039;comment__in&#039;,\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Pagination<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>number<\/code><\/td><td>int<\/td><td>&#8221;<\/td><td>Maximum comments to return<\/td><\/tr><tr><td><code>offset<\/code><\/td><td>int<\/td><td>0<\/td><td>Number of comments to skip<\/td><\/tr><tr><td><code>paged<\/code><\/td><td>int<\/td><td>1<\/td><td>Page number (used with <code>number<\/code>)<\/td><\/tr><tr><td><code>no_found_rows<\/code><\/td><td>bool<\/td><td>true<\/td><td>Skip counting total rows<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ First 10 comments\n$comments = get_comments( array(\n    &#039;number&#039; =&gt; 10,\n) );\n\n\/\/ Page 2, 10 per page\n$comments = get_comments( array(\n    &#039;number&#039; =&gt; 10,\n    &#039;paged&#039;  =&gt; 2,\n) );\n\n\/\/ Skip first 20, get next 10\n$comments = get_comments( array(\n    &#039;number&#039; =&gt; 10,\n    &#039;offset&#039; =&gt; 20,\n) );\n\n\/\/ Get total count for pagination\n$query = new WP_Comment_Query( array(\n    &#039;post_id&#039;       =&gt; 42,\n    &#039;number&#039;        =&gt; 10,\n    &#039;no_found_rows&#039; =&gt; false,\n) );\necho &quot;Page 1 of &quot; . $query-&gt;max_num_pages;<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Hierarchical\/Threading<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>hierarchical<\/code><\/td><td>bool<\/td><td>string<\/td><td>false<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Values:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>false<\/code> &#8211; Don&#8217;t include descendants<\/li><li><code>'threaded'<\/code> &#8211; Tree structure with children in <code>WP_Comment::$children<\/code><\/li><li><code>'flat'<\/code> &#8211; Flat array including all descendants<\/li><\/ul><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Threaded comments with children populated\n$comments = get_comments( array(\n    &#039;post_id&#039;      =&gt; 42,\n    &#039;parent&#039;       =&gt; 0,\n    &#039;hierarchical&#039; =&gt; &#039;threaded&#039;,\n) );\n\nforeach ( $comments as $comment ) {\n    display_comment( $comment );\n    foreach ( $comment-&gt;get_children() as $reply ) {\n        display_reply( $reply );\n    }\n}\n\n\/\/ Flat list of all comments including replies\n$comments = get_comments( array(\n    &#039;post_id&#039;      =&gt; 42,\n    &#039;hierarchical&#039; =&gt; &#039;flat&#039;,\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Meta Query<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>meta_key<\/code><\/td><td>string<\/td><td>string[]<\/td><td>&#8221;<\/td><\/tr><tr><td><code>meta_value<\/code><\/td><td>string<\/td><td>string[]<\/td><td>&#8221;<\/td><\/tr><tr><td><code>meta_compare<\/code><\/td><td>string<\/td><td>&#8216;=&#8217;<\/td><td>Comparison operator<\/td><\/tr><tr><td><code>meta_compare_key<\/code><\/td><td>string<\/td><td>&#8216;=&#8217;<\/td><td>Key comparison operator<\/td><\/tr><tr><td><code>meta_type<\/code><\/td><td>string<\/td><td>&#8216;CHAR&#8217;<\/td><td>Value cast type<\/td><\/tr><tr><td><code>meta_type_key<\/code><\/td><td>string<\/td><td>&#8221;<\/td><td>Key cast type<\/td><\/tr><tr><td><code>meta_query<\/code><\/td><td>array<\/td><td>&#8221;<\/td><td>Complex meta query<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Simple meta filter\n$comments = get_comments( array(\n    &#039;meta_key&#039;   =&gt; &#039;rating&#039;,\n    &#039;meta_value&#039; =&gt; 5,\n) );\n\n\/\/ Complex meta query\n$comments = get_comments( array(\n    &#039;meta_query&#039; =&gt; array(\n        &#039;relation&#039; =&gt; &#039;AND&#039;,\n        array(\n            &#039;key&#039;     =&gt; &#039;rating&#039;,\n            &#039;value&#039;   =&gt; 4,\n            &#039;compare&#039; =&gt; &#039;&gt;=&#039;,\n            &#039;type&#039;    =&gt; &#039;NUMERIC&#039;,\n        ),\n        array(\n            &#039;key&#039;     =&gt; &#039;verified&#039;,\n            &#039;value&#039;   =&gt; &#039;yes&#039;,\n        ),\n    ),\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Date Query<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>date_query<\/code><\/td><td>array<\/td><td>null<\/td><td>Date query clauses<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Comments from last 30 days\n$comments = get_comments( array(\n    &#039;date_query&#039; =&gt; array(\n        array(\n            &#039;after&#039; =&gt; &#039;30 days ago&#039;,\n        ),\n    ),\n) );\n\n\/\/ Comments from specific date range\n$comments = get_comments( array(\n    &#039;date_query&#039; =&gt; array(\n        array(\n            &#039;after&#039;     =&gt; &#039;January 1, 2024&#039;,\n            &#039;before&#039;    =&gt; &#039;March 31, 2024&#039;,\n            &#039;inclusive&#039; =&gt; true,\n        ),\n    ),\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Search<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>search<\/code><\/td><td>string<\/td><td>&#8221;<\/td><td>Search term<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Searches:<\/strong> <code>comment_author<\/code>, <code>comment_author_email<\/code>, <code>comment_author_url<\/code>, <code>comment_author_IP<\/code>, <code>comment_content<\/code><\/p><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$comments = get_comments( array(\n    &#039;search&#039; =&gt; &#039;wordpress&#039;,\n) );<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">Other Parameters<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>karma<\/code><\/td><td>int<\/td><td>&#8221;<\/td><td>Specific karma score<\/td><\/tr><tr><td><code>fields<\/code><\/td><td>string<\/td><td>&#8221;<\/td><td>&#8216;ids&#8217; for IDs only, empty for full objects<\/td><\/tr><tr><td><code>count<\/code><\/td><td>bool<\/td><td>false<\/td><td>Return count instead of comments<\/td><\/tr><tr><td><code>cache_domain<\/code><\/td><td>string<\/td><td>&#8216;core&#8217;<\/td><td>Cache key namespace<\/td><\/tr><tr><td><code>update_comment_meta_cache<\/code><\/td><td>bool<\/td><td>true<\/td><td>Prime meta cache<\/td><\/tr><tr><td><code>update_comment_post_cache<\/code><\/td><td>bool<\/td><td>false<\/td><td>Prime post cache<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Get IDs only\n$ids = get_comments( array(\n    &#039;post_id&#039; =&gt; 42,\n    &#039;fields&#039;  =&gt; &#039;ids&#039;,\n) );\n\n\/\/ Count comments\n$count = get_comments( array(\n    &#039;post_id&#039; =&gt; 42,\n    &#039;count&#039;   =&gt; true,\n) );<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Methods<\/h2><h3 class=\"wp-block-heading\">__construct()<\/h3><p>Sets up the query.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function __construct( $query = &#039;&#039; )<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">query()<\/h3><p>Executes the query.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function query( $query ): array|int<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">get_comments()<\/h3><p>Internal method that retrieves comments.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function get_comments(): int|int[]|WP_Comment[]<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">parse_query()<\/h3><p>Parses query arguments.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function parse_query( $query = &#039;&#039; )<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">SQL Clauses Filter<\/h2><p>The <code>comments_clauses<\/code> filter allows modifying the SQL query:<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">add_filter( &#039;comments_clauses&#039;, function( $clauses, $query ) {\n    \/\/ $clauses = array(\n    \/\/     &#039;fields&#039;  =&gt; &#039;SELECT ...&#039;,\n    \/\/     &#039;join&#039;    =&gt; &#039;JOIN ...&#039;,\n    \/\/     &#039;where&#039;   =&gt; &#039;WHERE ...&#039;,\n    \/\/     &#039;orderby&#039; =&gt; &#039;ORDER BY ...&#039;,\n    \/\/     &#039;limits&#039;  =&gt; &#039;LIMIT ...&#039;,\n    \/\/     &#039;groupby&#039; =&gt; &#039;GROUP BY ...&#039;,\n    \/\/ );\n    return $clauses;\n}, 10, 2 );<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Performance Tips<\/h2><ol class=\"wp-block-list\"><li><strong>Use <code>no_found_rows<\/code><\/strong> (default true) when you don&#8217;t need pagination counts<\/li><li><strong>Use <code>fields =&gt; 'ids'<\/code><\/strong> when you only need IDs<\/li><li><strong>Set <code>update_comment_meta_cache =&gt; false<\/code><\/strong> if you won&#8217;t access meta<\/li><li><strong>Use <code>update_comment_post_cache =&gt; true<\/code><\/strong> if accessing post properties<\/li><\/ol><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Optimized query for counting\n$count = get_comments( array(\n    &#039;post_id&#039;                   =&gt; 42,\n    &#039;count&#039;                     =&gt; true,\n    &#039;update_comment_meta_cache&#039; =&gt; false,\n) );<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Complete Example<\/h2><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Get paginated, threaded comments for a post\n$query = new WP_Comment_Query( array(\n    &#039;post_id&#039;                    =&gt; get_the_ID(),\n    &#039;status&#039;                     =&gt; &#039;approve&#039;,\n    &#039;parent&#039;                     =&gt; 0,\n    &#039;number&#039;                     =&gt; get_option( &#039;comments_per_page&#039; ),\n    &#039;paged&#039;                      =&gt; get_query_var( &#039;cpage&#039; ) ?: 1,\n    &#039;no_found_rows&#039;              =&gt; false,\n    &#039;hierarchical&#039;               =&gt; &#039;threaded&#039;,\n    &#039;update_comment_post_cache&#039;  =&gt; false,\n    &#039;include_unapproved&#039;         =&gt; is_user_logged_in() \n        ? array( get_current_user_id() ) \n        : array(),\n) );\n\n$comments = $query-&gt;comments;\n$total_pages = $query-&gt;max_num_pages;\n$total_comments = $query-&gt;found_comments;<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Core class for querying comments from the database. Since: 3.1.0 Source: wp-includes\/class-wp-comment-query.php Overview WP_Comment_Query retrieves comments based on specified criteria. It supports filtering, pagination, meta queries, date queries, and hierarchical&#8230;<\/p>\n","protected":false},"featured_media":0,"template":"","meta":{"footnotes":""},"tags":[],"project":[607],"project_type":[749],"class_list":["post-5556","documentation","type-documentation","status-publish","hentry","project-comments","project_type-wordpress-reference"],"project_info":{"id":589,"name":"WordPress Core","slug":"wordpress-core"},"project_type_info":{"id":749,"name":"WordPress Reference","slug":"wordpress-reference"},"_links":{"self":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/types\/documentation"}],"version-history":[{"count":3,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5556\/revisions"}],"predecessor-version":[{"id":8961,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5556\/revisions\/8961"}],"wp:attachment":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/media?parent=5556"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/tags?post=5556"},{"taxonomy":"project","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project?post=5556"},{"taxonomy":"project_type","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project_type?post=5556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}