[wp-trac] [WordPress Trac] #33170: get_comments interface doesn't return comments with 'comment' type
WordPress Trac
noreply at wordpress.org
Wed Jul 29 09:25:56 UTC 2015
#33170: get_comments interface doesn't return comments with 'comment' type
--------------------------+-----------------------------
Reporter: caramon | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 4.2.3
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hi,
I'm using a theme which gets comments via get_comments interface. The call
looks like this:
{{{
#!php
$comment_entries = get_comments(array('type' => 'comment', 'post_id' =>
$post->ID));
}}}
I noticed that a post has some comments but theme isn't display them.
After some debugging I found that the call above sends invalid SQL query
to DB. The query looks like this:
{{{
#!sql
SELECT * FROM wp_comments
WHERE
((comment_approved = '0' OR comment_approved = '1')) AND comment_post_ID
= 234 AND comment_type IN ('')
ORDER BY
wp_comments.comment_date_gmt DESC
}}}
The problem with SQL is content_type in value is empty. In the DB records
wp_comment.comment_type has 'comment' value, so it simply doesn't match to
SQL that WP generates.
I managed to fix the problem by changing wp-include/comment.php file. The
diff looks like this:
{{{
#!diff
--- comment.php 2015-07-18 22:30:24.511615735 +0300
+++ comment.php.new 2015-07-29 12:13:26.155001197 +0300
@@ -741,7 +741,7 @@
case 'comment':
case 'comments':
- $comment_types[ $operator
][] = "''";
+ $comment_types[ $operator
][] = "'comment'";
break;
case 'pings':
}}}
I don't think that my solution is the right one but I think you should get
an idea how the bug can be fixed. :)
Thanks for reading it.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33170>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list