Comments Filtering for MP-WP



November 29th, 2019 by Diana Coman

To fix the Recent Comments widget so that it stops messing about with trackbacks/pingbacks where they don't belong (aka in your sidebar), you'll need just a tiny change to wp-includes/widgets.php so that it becomes a bit more discerning when selecting stuff from the comments table1, quoth the .vpatch:

- $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
+ $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' and comment_type = '' ORDER BY comment_date_gmt DESC LIMIT $number");

And to make this .vpatch worth at least two lines instead of just one, I also fixed the "default" theme so that it orders the comments at the bottom of an article: trackbacks and pingbacks should be shown there but *only* at the bottom, not messing up people's conversation. The change is made in wp-content/themes/default/comments.php as the .vpatch says:

< ol class="commentlist" >
- < ?php wp_list_comments(); ? >
+ < ?php wp_list_comments('type=comment'); ? >
+ < ?php wp_list_comments('type=pings'); ?>
< /ol >

While I looked into applying the same approach to fix the "classic" theme too, the sadness is that the classic theme takes a different approach to comments and so the required change wasn't that obvious to me right now. I'm no expert in php or mp-wp and I'm not all that keen at becoming one either so I left it for now at this and I have no claim that the solution is anything other than something that works on my blog.

The .vpatch sits on top of billymg's current v-tree head and hopefully doesn't break anything but I'm sure he'll let me know if it does2 :


  1. line 1392 in my file 

  2. According to the "no news is good news" principle, if he doesn't complain, then I'll consider it's all absolutely perfect. 

Comments feed: RSS 2.0

8 Responses to “Comments Filtering for MP-WP”

  1. Diana Coman says:

    Adding for future reference & readers:

    mircea_popescu: incidentally -- there's a divergence in your patch. on the first heading you say and comment_type = '' but on the second heading you say
    mircea_popescu: +
    mircea_popescu: it's really the same conditional, shouldn't it rather be and comment_type = comment' ?
    diana_coman: mircea_popescu: that's in mpwp, what can I do if it does same thing in 2 different ways?
    diana_coman: in one place it does a direct select in db ; in the other it uses its own function and that has its own parameters
    diana_coman: and yes, it annoyed me.
    mircea_popescu: you're doing the same thing in two different ways -- one place you ask for an empty type, the other for a "comment" type
    mircea_popescu: the function is just a wrapper on the exact same thing, wp_list_comments('type=comment'); is exactly SELECT * FROM $wpdb->comments WHERE comment_approved = '1' and comment_type = 'comment'
    diana_coman: it's mpwp that does same thing in two different ways; all I do is to conform to its different ways; and no; in db the comment_type is (as I checked) with 3 distinct values: empty string, "trackback" or "pingback"
    diana_coman: no "pings" for instance; but that wp_list_comments method has specific parameters at least according to docs
    diana_coman: respectively "comment" or "pings"
    mircea_popescu: no fucking wayu, really this dumb ?!
    diana_coman: so that's on mpwp not on me
    diana_coman: what can I tell you.
    diana_coman: this sort of shit is what I spent those 10 minutes on.

  2. billymg says:

    This looks good to me!

    lol at the inconsistency between "" and "comment" meaning the same thing. If I had to guess I'd say the pingback type comments were added in a later version, and rather than have users migrate their existing comments to become type: 'comment' they just added the new types and decided a blank type would represent the "original" type of comment.

  3. Diana Coman says:

    Thanks for the confirmation that it's all fine.

    Re '' and 'comment', I think there is what you say there + the idea of "we'll make a wrapper php function to hide the pesky internals and so we get to call stuff something else (because why not)". And then of course, one gets direct select in some places and wrapper function in others.

  4. billymg says:

    I went to test locally and noticed the signature link in your article has some extra cruft in the path that causes it to 404. I was able to grab it from http://ossasepia.com/vpatches/mp-wp_comments_filtering.vpatch.diana_coman.sig just fine though!

  5. Diana Coman says:

    Fixed it now, thanks for letting me know! (I had forgotten the http at front, so it considered it relative path and prefixed it with the site's address, hence the mess.)

  6. [...] two weeks ago, I took one hour to produce and publish a tiny vpatch on the mp-wp V-tree, with the whole experience triggering for me a need to look at V1 again, as noted in the logs: [...]

  7. [...] mp-wp_comments_filtering.vpatch (diana_coman) (sauce) [...]

  8. [...] yet non-obvious changes you can make to a new installation of MP's WordPress, right up there with separating pingbacks from direct comments and chapter-and-verse [...]

Leave a Reply to billymg