Home/ Journal Bens Projects Binary Moon Archives About Ben Gillbanks Subscribe to Binary Moon Updates

Subscribe to Binary Moon Website Updates, it's Free and Easy to Stay in Touch

Search Binary Moon

Search Binary Moon

WordPress Http – Read Content From Other Websites

Recently I have been doing a lot of work with API's and these often involve loading text content (rss/ xml/ json etc) from another website and then displaying the results - for instance the Twitter feed at the bottom of this website uses the Twitter Search API to get my latest updates.

There are all sorts of ways to access this data, but different servers require different methods so it's good to have a generic method for accessing the data... and WordPress has one built in. Even better; it's really easy to use.

WordPress Http - WP_Http

Below is a really basic usage for the plugin that will grab the 5 latest items from my Twitter stream and stick them in an array called $content. You can read up on the Twitter search API here.

$url = 'http://search.twitter.com/search.json?q=from%3Abinarymoon&rpp=5';

$request = new WP_Http;
$result = $request->request($url);
$content = array();

if (isset($result->errors)) {
	// display error message of some sort
} else {
	$content = $result['body'];
}

Other places this could be used include (but are not limited to):

  • In my theme The Local I use it to grab the current weaterht for the specified location
  • In Accumulo it's used to load the RSS feeds that you can see on the homepage
  • Many WordPress plugins use similar functionality to get data for other webservices such as loading Flickr galleries

Is there anything else you can think of that this could be used for?

5 Responses to “WordPress Http – Read Content From Other Websites” Leave a reply ›

  • Is this a new feature? I can this of some serious time working with cURL and other functions when using WordPress. Is it in 2.8? Think thats what my site is running ... I might be working with an API in my next plugin so this is a really helpful find! Cheers Ben!

    • I think this method has been around for a version or two - before this they used a system called Snoopy which is still available but has been deprecated so could be removed at any time.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About me

About BenMy name is Ben Gillbanks. I'm a lover of Video Games, WordPress, Web Development and everything in between.

I have been working on the internet since 1998, and working with computers even longer. I am a hardcore Nintendo fanboy and have owned most of their consoles at one stage or another.

Read more about me on my about page.


Follow Me


Random Link-outs

The Binary Network links to all my websites
bengillbanks.co.uk - Ben Gillbanks

Ben Gillbanks

All my websites under 1 roof, the easiest way to find out what I do

Pro Theme Design - premium WordPress themes

Pro Theme Design

Premium WordPress themes by web design pros (erm... that includes me)

Binary Joy - gaming news and reviews

Binary Joy

Gaming news and reviews

Binary Sun - play free online games

Binary Sun

Play and download free and paid games (many made by me)

Gaming Angel - download and play games online

Gaming Angel

Stacks of shareware games, free to try and cheap to buy