Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted
+25
  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
share|improve this answer
    
Make a lot of sense, looks like it will be the ideal solution, will try implementing it and report back, thanks! –  drtanz Aug 11 '12 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 Aug 13 '12 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. –  drtanz Aug 15 '12 at 14:53
1  
Check my answer for an example. –  Jasper Denkers Aug 15 '12 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. –  drtanz Aug 23 '12 at 22:45
show 4 more comments
  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.
share|improve this answer
    
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? –  drtanz Jul 11 '12 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 –  TheDeadMedic Jul 11 '12 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. –  drtanz Aug 9 '12 at 14:48
    
That wasn't quite what I meant - take guidance from the plugin & implement the term meta yourself. –  TheDeadMedic Aug 9 '12 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. –  TheDeadMedic Aug 13 '12 at 15:49
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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