Good way to store content and settings for an RSS plugin

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.

Read More

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.

Related posts

Leave a Reply

2 comments

    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 );
    endwhile;
    
    wp_reset_postdata();
    
    // now $items contains your feed items from the feeds in the feed_category with id 123
    
    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.