Comments Feed & Custom Post Statuses

I have added 2 post statuses to regular posts. They are “resolved” and “unresolved” – essentially basic tracking for issues. Both are registered as “public”. Posts from these statuses are displayed in the post RSS feed. However, comments added to posts with these statuses do not show in the comments feed. Comments added to regular “published” posts appear just fine. I have checked and the feed cache is getting updated when a new comment is added to a resolved/unresolved post and have double checked and all comments are listed as “approved” but still they do not display.

I have done quite a bit of exploring of the WP source trying to determine why this would be, but I cannot. I have even tried to manually adding my posts statuses to the WP_Query object before fetching the posts with no result. The feed itself uses a WP_Query object, but I cannot figure out if there are also calls to WP_Comment_Query or not. The WP_Query object has the “with_comments” flag set.

So does anyone have any idea why this would happen? My assumption is that somewhere in the chain of queries they are specifically targeting “published” posts but have to figure out where, or what hook I might use to change it.

Here is the code for registering my statuses:

function resolved_unresolved_status() {
  register_post_status('resolved',
    array(
      'label' => _x('Resolved', 'post'),
      'public' => true,
      'exclude_from_search' => false,
      'show_in_admin_all_list' => true,
      'show_in_admin_status_list' => true,
      'label_count' => _n_noop('Resolved <span class="count">(%s)</span>', 'Resolved <span class="count">(%s)</span>')
    )
  );

  register_post_status('unresolved',
    array(
      'label' => _x('Unresolved', 'post'),
      'public' => true,
      'exclude_from_search' => false,
      'show_in_admin_all_list' => true,
      'show_in_admin_status_list' => true,
      'label_count' => _n_noop('Unresolved <span class="count">(%s)</span>', 'Unresolved <span class="count">(%s)</span>')
    )
  );
}

add_action('init', __NAMESPACE__ . '\\resolved_unresolved_status');

And here I tried to use pre_get_posts filter to force my statuses with no luck:

function alter_feed_query($query) {
        if($query->is_comment_feed) {
                $query->set('post_status', array('publish', 'resolved', 'unresolved'));
        }
        return $query;
}
add_filter('pre_get_posts', __NAMESPACE__ . '\\alter_feed_query');

1 Answer
1

Found the filter: comment_feed_where to filter the WHERE clause, which by default only looks for posts with status = publish.

function comment_feed_where_status($where) {
        return str_replace(
                "post_status="publish"",
                "post_status="publish" OR post_status="resolved" OR post_status="unresolved"",
                $one);
}
add_filter('comment_feed_where', __NAMESPACE__ . '\\comment_feed_where_status');

I found this by debugging with “SAVEQUERIES” enabled and dumping the queries array on the feed page.

Leave a Comment