RSS Club for WordPress

This post is secret; it’s only publicised via my RSS feed. Thanks for being part of RSS Club!

I’ve started publishing posts that are only publicised on my RSS feed (and places that syndicate it, I suppose), not on the HTML pages of my blog nor via any social media channels. It’s a concept promoted by Dave Rupert as “RSS Club”. Of it, he says:

What kind of content should you post? Whatever you want. More personal, less personal, weird. It doesn’t matter.

These posts aren’t very “secret”; they’re at publicly-accessible web addresses and linked from a publicly-accessible, promoted feed. But in an era where feed readers don’t enjoy the popularity they once had (and perhaps still ought to have!), it provides a fun and quirky way to artificially reduce the audience that some of your blog posts get. So I’m enjoying playing with it a bit.

I came across the idea via Jim Nielsen‘s blog, and I’ve wanted to get in on the action for a while, but I’d been putting off getting the code in place to support it. Dave uses Jekyll, so he just had to tweak his buildchain to not include his “RSS only” posts. I assume Jim’s process was similar (he’s powered by Metalsmith). But me? I’ve got multiple decades of history in WordPress format, and I can’t see that changing anytime soon, so I needed to roll my sleeves up and get hacky before I could join the club.

I tried Lutz Schröer‘s plugin, which should have “just worked”, but it didn’t: probably because of the huge stack of custom code I’m already running on this site! So instead I came up with my own. My goals were:

  1. Posts with the “rss club” tag should not appear on listing pages, blog search results, previous/next post links, the homepage, or in the “related posts” section.
  2. But these posts should be visible if you go directly to their URL, as well as in RSS feeds, and if you go to the listing page that specifically shows all posts with that tag (incidentally, WordPress takes this setup and ensures I have an RSS feed of just the “RSS only” posts!).

My resulting code turned out tiny – much smaller than the plugin I couldn’t make work – so I just dumped it into my theme’s functions.php. In case it’s any use to you, here it is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Posts tagged "rss-club" shouldn't appear outside of RSS, so:
// 1. Prevent main queries from returning such posts, except in RSS feeds:
function rss_club_pre_get_posts($query){
  if ( is_admin() ) return; // always see rss club posts in the admin interface
  if ( is_feed() ) return; // always see rss club posts in RSS feeds, duh
  if ( is_tag( 'rss-club' ) ) return; // if we've found the rss-club tag and we're specifically looking for things in it, show them
  $tag = get_term_by('slug', 'rss-club', 'post_tag');
  if ( ! $tag ) return; // if we don't have an rss-club tag, drop out here
  // filter the query:
  $query->set( 'tag__not_in', $tag->term_id );
}
add_action( 'pre_get_posts', 'rss_club_pre_get_posts' );

// 2. Previous prev/next links "skip over" such posts:
function rss_club_prev_next_where($where){
  global $wpdb;
  $secret_post_ids = array_map('array_shift', $wpdb->get_results('SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id=1137', ARRAY_N)); // need to use wpdb so we don't hit our own hook above!
  $secret_post_ids[] = -1; // add a dummy item to ensure the SQL is valid even if there are no secret posts
  $secret_post_ids_list = implode(',', $secret_post_ids);
  // Append our filter onto the query:
  return $where . " AND p.id NOT IN ($secret_post_ids_list)";
}
add_action( 'get_previous_post_where', 'rss_club_prev_next_where' );
add_action( 'get_next_post_where', 'rss_club_prev_next_where' );

1 reply to RSS Club for WordPress

  1. This comment exists to automate testing that I’m successfully suppressing publication (except via RSS) of comments attached to “rss club” posts. Otherwise there’s a potential leak there!

Leave a Reply

Your email address will not be published. Required fields are marked *