Peter asked me if it is possible to change my RSS feed for my comments. Right now it contains any reaction, which come in the form of webmentions, likes, reposts, as well as actual replies and comments. Essentially it is currently not a comment feed, but a reaction feed. As part of my site tweaks I will see if I can turn it into a real comment feed (that includes webmentions that are replies), and how to change the way some things are displayed (I had that but it got overwritten by plugin updates).

For now I have renamed the comment feed, so new subscribers have the right expectations.

2 reactions on “

  1. In response to Peter’s earlier request I have created a new RSS feed that contains only comments on postings, not other types of reactions such as likes, mentions, and ping- or trackbacks. It was a bit of a puzzle to get it all working, having me dive down the rabbit hole leading to the maze that is the WordPress documentation. With some suggestions from Jan Boddez, I now have a result. The new feed is listed on the right hand side. Subscribe to it if you care to follow conversations on this blog. The feed with all interactions, so including likes etc., is also available.
    I documented how I created the feed over in the wiki.

  2. I am trying to add an additional RSS feed, using a different template, to my blog. Most documentation on WordPress.org seems to be aimed at replacing an existing feed, or alter its contents.
    The additional feed is meant to fulfill Peter’s request to have a comments feed that shows only real comments, not all the likes, reposts etc I also receive through WebMentions. It is a very logical request, but I also want to keep the original comments RSS feed that includes all interaction with content on this site. So I need to add a new RSS feed.
    WordPress.org doesn’t really contain any complete step-by-step explanations for anything, including for adding customised RSS feeds. It also doesn’t have any info on excluding pingbacks from comment feeds, which would be similar to what I’m trying to do. I tried stuff based on snippets of documentation I did find, but couldn’t put those snippets together into a coherent path to a solution.
    Then I found a guide at WPBeginner dot com (WP beginner, that’s me, even though I’ve been a WP user and tinkerer since 2004) It’s from 2016 so maybe not concurrent with today’s version of WP. Following their explanation, I added the following to my child theme’s functions.php:
    add_action('init', 'extracommentsRSS');
    function extracommentsRSS(){
    add_feed('commentsdupe', 'extracommentsrssFunc');
    }

    function extracommentsrssFunc() {
    get_template_part(‘rss2’, ‘commentsdupe’);
    }
    The first part adds the new feed to WP, the second function tells it where to look for the template for the feed. That template, named rss2-commentsdupe.php, is located within the child-theme folder.
    The URL for the feed now works, however it first prompted a download of an empty file due to the template file having a wrong name. With that name corrected (based on Jan’s comments below), it does load the template correctly.
    The template itself still has issues (meaning it doesn’t work as intended at all): the while has_comments() loop provides no results, as it does not get passed any variables. Because the get_template_part is not provided with those variables before getting called. Jan suggested adding the query to the template. Did that, but now struggle to find a way to lift the comments from the query result.
    The query below gets the latest 20 approved reactions on my site of the type ‘comment’ (as opposed to e.g. pingback or webmention):
    $query = new WP_Comment_Query( array( 'status' => 'approve', 'type' => 'comment', 'number' => 20, 'orderby' => 'commentdate_date' ) );
    The result if I print it as arrays, contains 7 elements (the query, the query arguments, default query arguments (?), an empty one, an array with the 20 requested WP comment objects, and two more empty ones).
    The query works as intended, but now I do not know how a) to access the 5th element, and b) handle the WP comment objects within it. What seems to be intended functions for it (have_comments(), the_comment()) don’t seem to work.
    The below code at least does not work. If I test it like this, it never enters the while loop, so never echoes ‘BOE’
    while ( $query->have_comments() ) :
    echo 'BOE';
    $query->the_comment();
    $comment_post = get_post( $comment->comment_post_ID );
    $GLOBALS['post'] = $comment_post;
    ?> etc.

    After some more suggestions by Jan Boddez, ao that have_comments() doesn’t work for wp_comment_query, I then established that get_comments to query the comments, and then a foreach to loop through them works the way I need it to.
    $query = get_comments( array( 'status' => 'approve', 'type' => 'comment', 'number' => 20, 'orderby' => 'commentdate_date' ) );
    foreach ($query as $comment):
    $comment_post = get_post( $comment->comment_post_ID );
    $GLOBALS[‘post’] = $comment_post;
    Once I had that the original feed template could be fully re-used, and now validates:

Comments are closed.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)

Mentions

  • 💬 How to Add a Custom RSS Feed to WordPress – Interdependent Thoughts
  • 💬 Ton Zijlstra