I am building an RSS reader plugin and I'd like some advice on how to store the data and settings for this plugin.

The idea is to be able to enter a set of feed sources and associate each one of these sources with one or more categories. Thus you can have several categories e.g. sports, politics each having their own associated feed sources.

So for example:

  • Sports
    • ESPN.com
    • Sportingnews.com

When the feed items from these feed sources are imported every few hours via Cron they are then stored as custom post types. Each feed item must of course be associated with the feed source.

When it comes to display feed items the plugin will use this logic:

  1. Check which category is being called (via shortcode)
  2. Check which feed sources are associated with that category
  3. Get feed items associated with feed sources identified in step 2

I am still unsure about how all this data needs to be stored.

The plugin will have a settings page and for that I am settled about storing everything in the wp_options table.

However when it comes to the feed sources, categories and feed items, I'm still confused how to store them best.

Any suggestions on how to do this?

I've been reading about the CPTonomies plugin which seems to do what I need, but I want the functionality in built into this plugin and I cannot use another external plugin.

2 Answers 2

  1. Add a Custom Post Type called 'feed'
  2. Add a Custom Taxonomy for 'feed' called 'feed_category'
  3. As you mentioned, use a Custom Post Type for your feed items, for example 'feed_item'
  4. When adding an 'feed_item', add post_meta which makes the link between 'feed' and 'feed_item'. For example update_post_meta( $item_id, 'feed', $feed_id );

Your loop can be used perfectly when using my suggested structure. At step 3 you query all posts with post meta 'feed_id' = $feed_id.

Codex Links:

To get the feed items use the following code:

$category_id = 123;

$the_query = new WP_Query( array(
    'post_type' => 'feed',
    'feed_category' => $category_id
) );

$items = array();

while ( $the_query->have_posts() ) : $the_query->the_post();
    $feed_items = get_posts( array(
        'post_type' => 'feed_item',
        'meta_key' => 'feed_id',
        'meta_value' => $post->ID,
        'numberposts' => -1
    ) );

    $items = array_merge( $items, $feed_items );


// now $items contains your feed items from the feeds in the feed_category with id 123
  • Make a lot of sense, looks like it will be the ideal solution, will try implementing it and report back, thanks!
    – urok93
    Commented Aug 11, 2012 at 20:12
  • @JasperDenkers Please always take yourself enough time to format your answers (&questions) properly. That's why we got the WYSIWG editor. Thanks.
    – kaiser
    Commented Aug 13, 2012 at 13:23
  • How do I write the query that selects all the feed items needed, based on the category the user has selected? I'm with organising the data as suggested, but am struggling to write the query that can get the data required. To recap, the query must use info from both the 2 custom post types and the taxonomy, because it needs to retrieve all feed items (together with feed source info for each item), that are associated (through their feed source) with the selected category.
    – urok93
    Commented Aug 15, 2012 at 14:53
  • 1
    Check my answer for an example. Commented Aug 15, 2012 at 18:16
  • Have you tested that code Jasper? merge_array should be array_merge I think, and I'm not sure $items should be the first array passed in there.
    – urok93
    Commented Aug 23, 2012 at 22:45
  1. Store global plugin settings in the options table - update_option(), get_option() etc.
  2. Store content in the posts table (either as regular posts/pages, or custom post types)
  3. Group/categorise content with taxonomies - wp_set_object_terms() etc.
  4. Store content-specific settings in the post meta table - update_post_meta(), get_post_meta() etc.
  • I agree with 1,2,3. For 4 you are referring to the setting of feed sources and their categories right? Aren't entries in the post meta associated with particular posts? I was thinking of making two custom post types: - feeds - feed items and sharing the categorisation taxonomy between them. Would that make sense?
    – urok93
    Commented Jul 11, 2012 at 11:10
  • If you want to store arbitrary data per category (term), it might be worth considering term meta. Otherwise you can always stick with a serialized array in the options table, or naming option keys along the lines of term_{term_id}_config Commented Jul 11, 2012 at 11:50
  • Using another plugin to achieve this is not my goal, as I am myself building this functionality in a plugin, and therefore it doesn't make sense to ask users to have to download yet another plugin for this to work.
    – urok93
    Commented Aug 9, 2012 at 14:48
  • That wasn't quite what I meant - take guidance from the plugin & implement the term meta yourself. Commented Aug 9, 2012 at 15:11
  • 1
    Too many repercussions; what if the user still wants to use the description field? What if other plugins levy the description (SEO etc.)? Too many possible places you'd need to consider about hooking into so that everything behaves as normal. I guess if this were a localised solution I'd consider it, but certainly not for the wild. Commented Aug 13, 2012 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.