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 know how to retrieve the rss2 feed from a category in wp, namely adding /feed behind the category name. However when I do this, not all entries from that feed are included in the rss, this is because I set the feed restriction to be 50 at the admin backend.

I would like to know if a feed length could be set indiviually for each category/feed programatically.

I could not find any api settings for the size of the feeds ... any help is welcome here.

Thanks for your help.

share|improve this question
    
Stephen Harris and CodeMonkey the answers both do not work for one particular category? Otherwise both answers work do work for me! Why could it be that it only does not work for one category? –  mahatmanich Nov 15 '12 at 15:17
add comment

2 Answers

up vote 8 down vote accepted
+50

You should be able to use pre_get_posts and set the posts_per_page to 50 conditionally (on being feed for categories). Unfortunately there is this unresolved trac ticket.

The only work-around is to do hook into post_limits and replace the LIMIT part of the SQL query directly.

add_action('post_limits','wpse71759_category_rss_limit',10,2);
function wpse71759_category_rss_limit($limit, $query){

     if( $query->is_feed() && $query->is_category() ){
          $paged =  $query->get('paged') ? (int) $query->get('paged') : 1;
          $per_page = 50;
          $page_start = ($paged-1)*$per_page;

          return "LIMIT $page_start, $per_page";
     }
     return $limit;
}
share|improve this answer
    
Hey Stephen I will look into that, uhm actually I always want all entries from a category in a feed, and only on my blog page I want a restriction of the limit that I set in the backend, how would I do that? –  mahatmanich Nov 13 '12 at 1:12
    
In that case, return ""; rather than "LIMIT $page_start, $per_page" should do it. –  Stephen Harris Nov 13 '12 at 10:41
    
Hey can you explain your code a bit? I am not quite sure if that is what I want what that you are offering here. –  mahatmanich Nov 15 '12 at 14:42
    
So for category feeds you want to return all posts - so you don't want a LIMIT part to your query. The above filter, allows you to replace the LIMIT part with a blank string, so that the resulting sql will fetch all posts. –  Stephen Harris Nov 15 '12 at 14:45
1  
Yes, but I'd recommend making a plug-in out of it (wpcandy.com/teaches/how-to-create-a-functionality-plugin) –  Stephen Harris Nov 15 '12 at 14:54
show 4 more comments
add_filter('query', 'sql_query_feed_filter');
function sql_query_feed_filter($sql){
    global $wp_query;

    if ($wp_query->is_feed == true &&  isset($wp_query->query_vars['custom_taxonomy']) &&  in_array($wp_query->query_vars['custom_taxonomy'], array('slug1','slug2')) ){
        if (strpos($sql, 'SELECT SQL_CALC_FOUND_ROWS') !== false){
            list($sql,) = explode('LIMIT', $sql);
        }
    }
    return $sql;
}

all you need to do is just edit this function and repalce taxonomy by your category taxonomy and edit slug to much your category...

share|improve this answer
    
Would you care to explain your code? –  mahatmanich Nov 14 '12 at 23:12
    
Simple SQL Query filter that trigger on feed ($wp_query->is_feed == true) if specific taxonomy found ($wp_query->query_vars['custom_taxonomy'] custom_taxonomy in example) and if it quivaluent to some slug ( $wp_query->query_vars['custom_taxonomy'] == 'slug' ). if everything of this happens and true (on a site.com/your-custom-feed-for-category.xml ) you will get no limit results in your feed ($SQL statment divided by LIMIT value which mean it returned without last LIMIT operator... no limit. all entries per rss.) –  Oleg Butuzov Nov 15 '12 at 9:16
    
Where would I drop that code? functions.php of my theme? –  mahatmanich Nov 15 '12 at 9:34
    
functions.php perfactly fits. but change slug and name of custom taxonomy before. and clear browser cache before testing (RSS Feeds a cached by browser). –  Oleg Butuzov Nov 15 '12 at 9:35
    
Hey thanks for the heads up with the cache! It kind of works, but still on at least one category I will not get all posts in the feed, on others it works ... –  mahatmanich Nov 15 '12 at 14:44
show 2 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.