Opened 10 years ago
Closed 9 years ago
#33170 closed defect (bug) (invalid)
get_comments interface doesn't return comments with 'comment' type
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.2.3 |
Component: | Comments | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
Hi,
I'm using a theme which gets comments via get_comments interface. The call looks like this:
$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:
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:
-
comment.php
old new 741 741 742 742 case 'comment': 743 743 case 'comments': 744 $comment_types[ $operator ][] = "' '";744 $comment_types[ $operator ][] = "'comment'"; 745 745 break; 746 746 747 747 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.
Change History (4)
This ticket was mentioned in Slack in #core by boone. View the logs.
9 years ago
#4
@
9 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
@caramon Welcome to Trac. As Boone mentioned above the query is working as intended, "comments" have a comment_type
of ''
in the database (weird, I know!).
I am closing this ticket, but feel free to re-open if I am mis-understanding.
Hi caramon - Thanks for the report, and welcome to WordPress Trac!
comment_type IN ('')
is not invalid SQL. It looks for rows where thecomment_type
field is an empty string.Normal WordPress comments - those created via wp-comments-post.php - have
comment_type = ''
. See https://core.trac.wordpress.org/browser/tags/4.3/src/wp-comments-post.php?marks=119#L118. If you have records in your database where the value in thecomment_type
field is 'comment', it might be a plugin at work. Can you verify this behavior with all plugins disabled?