12

I'm wondering how/if I can access more than the most recent X posts defined in the wordpress settings. I've seen plugins that migrate all blog content through RSS, haven't poked around to see their methods.

Basically I manage a couple hundred WordPress blogs, and I'm building a newsletter generator for my clients. They want to be able to select a few posts and have the excerpts appear in the newsletter body. The sites are spread across multiple servers and the newsletter generator is being built on top of our CRM, so direct database queries would be difficult. RSS would be the cleanest, but I can't seem to figure out how to access more than 10 at a time (when 10 is set in the admin).

Any ideas?

1
  • what do you mean by "10 is set in the admin"?
    – gcb
    Commented Apr 20, 2011 at 21:37

7 Answers 7

5

Codex has example snippet on how to use post_limits filter to override amount set in admin for feed.

if (isset ($query->query_vars['feed']) and ($query->query_vars['feed'] == 'ics')) 
    add_filter('post_limits','__return_empty_string'); 

http://codex.wordpress.org/Function_Reference/query_posts#Usage_Tips

2
  • 1
    This may be an option, but I was hoping to avoid having to modify theme code on 700+ sites.
    – bhamrick
    Commented Dec 1, 2010 at 19:35
  • 1
    So this is what I ended up doing. My sites are spread across a handful of WordPress-Mu installs, so it's not literally hundreds of differing instances of WordPress on hundreds of servers. The problem was that I needed this functionality on only SOME of the sites within each Mu install. So I wrote a plugin that does this, wrote a script that updated the database to activate that plugin on the sites I needed. Done. Thanks for the help.
    – bhamrick
    Commented Dec 3, 2010 at 0:46
27

A way to get your posts is to call the different pages of the rss feed in your newsletter generator. It's a safe approach that doesn't require to update your various Wordpress installations:

yourwebsite.com/feed -> get last 10 posts

yourwebsite.com/feed/?paged=2 -> get next 10 posts

And so on.

1
  • This! Really helpful for a lot of usecases. Commented Sep 9, 2022 at 11:03
4

Unfortunately, what you're trying to do is generally frowned upon in most communities. What I hear you asking for is:

  • A way to remotely retrieve more than the default number of (recent posts)
  • Possibly retrieve all published posts for a site
  • Without having any direct interaction with the site itself (using RSS)

This is a practice commonly used to scrape content from blogs and republish it without the permission of the original author. That's why I say it's generally frowned upon. Most blog authors put a lot of time and energy into developing great content, so making it easy for a third party to leverage their hard work to add SEO credit to their own site is ... well ... sleezy.

That said, I will assume for the moment that you have legitimate reasons for scraping content from over 700 sites. In that case, I would recommend a separate, programatic method - not RSS. If you have legitimate login information for all of these sites (i.e. they are your sites and not someone else's) you can use WordPress built-in XML-RPC features to fetch the content.

Use the built-in XML-RPC library to pass a request to metaWeblog.getRecentPosts specifying the ID of the blog (usually 0 for single sites, but could be different in multi-site), your WordPress username, your WordPress password, and the number of posts to fetch (set this to -1 to receive them all).

The other site will respond with (a rather large) XML file containing the content which you can do with what you want. This can all happen behind the scenes, and the metaWeblog.getRecentPosts request will give you much more information than an RSS feed (including custom fields, which might be important to you).

3

While not "all posts", I'd argue that a limit param is much more useful.

I would recommend directly filtering the "posts_per_rss" option as such:

add_filter( 'option_posts_per_rss', 'my_posts_per_rss' );
function my_posts_per_rss( $option ) {
    if( isset( $_GET['limit'] ) ) {
        return (int) $_GET['limit'] ?: $option;
    }
    return $option;
}

The feed could then be accessed like so: http://example.org/category/acme/feed/?limit=999

2

If memory serves, passing -1 as the number of posts has the same effect. Not entirely sure how it gets tossed into a URL, though.

As an aside, if you're really into having 700+ sites, consider having a cron that svn updates or git pulls from a stable branch, from a private repository on a daily basis... Combined with a daily http call to wp-admin/upgrade.php. It'll save you a lot of hassles when upgrading or tweaking your sites -- in that it'll get done automatically.

0

you may want to use some RSS aggregator like FeedWordpress

0

If you go to Settings > Reading > and change the value in the "Syndication feeds show the most recent" to a number that suits you, it will show up to the number of feeds you input.

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.