How to Pull WordPress Posts into External Website

Beacon Blog Article

By Beacon News | Published January 14, 2013 | Categories: Web Development

wordpress logoI'm sure there are many ways to pull WordPress posts into an external website but here I would like to offer up a simple custom XML solution. No matter what back-end/server-side technology being used (PHP, ASP, ASP.NET, ColdFusion, Ruby, Perl etc.) on the non-WordPress site, most will offer up a way to parse external XML. The problem however is that the out of the box WordPress feed does not include the full post content and limits you to 10 posts. We will need to create a custom feed that will not only provide full post content depending on the ID specified but also allow us to get an unlimited number of posts for our listing page.

Creating WordPress Custom Feed

Copy/paste the following into a new file at the root of your WordPress installation.
<?php define('WP_USE_THEMES', false);

$num = $_GET["numberposts"] ?: '10';
$cat = $_GET["catid"];
$postID = $_GET["postid"];
$type = $_GET["type"];

switch ($type){
   case "singlePost":
      $posts = get_posts('p='.$postID.'&amp;numberposts=1');
   case "catFeed":
      $posts = get_posts('category='.$cat.'&amp;numberposts='.$num.'&amp;order=ASC');
      $posts = get_posts('numberposts='.$num.'&amp;order=ASC');
      <?php if($type == "catFeed"){ ?>
         <catname><?php echo get_cat_name($cat); ?></catname>
         <catdescription><?php echo category_description($cat); ?></catdescription>
      <?php } ?>
      <?php foreach ($posts as $post) : start_wp(); ?>
            <id><?php the_id();?></id>
            <title><![CDATA[<?php the_title();?>]]></title>
            <link><?php the_permalink_rss() ?></link>
            <author><?php the_author();?></author>
            <pubDate><?php the_date();?></pubDate>
            <teaser><![CDATA[<?php the_excerpt();?>]]></teaser>
            <?php if($type == "singlePost"){ ?>
               <content><![CDATA[<?php the_content();?>]]></content>
            <?php } ?>
      <?php endforeach; ?>

As you will see if you go to the page URL the feed will default to all posts and the number that displays defaults to 10. To get exactly what content you want in the custom xml feed we will need to use QueryStrings.

URL QueryString Parameters

  • type – Feed type
    • singlePost – only pulls post that matches post id parameter
    • catFeed – shows a listing of posts from a category
    • default – all posts
  • postid – post id of the post you’d like to retrieve (only applies to singlePost)
  • catid – category id of the category to pull in (only applies to catFeed, optional)
  • numberposts – number of posts to display (defaults to 10)


  • – get 100 of the most recent posts in category with the ID of 244
  • – get a single post with the id of 13

XML Structure

   <catname>category name</catname>
   <catdescription>category description</catdescription>
         <id>post id</id>
         <pubDate>December 23, 2008</pubDate>
         <content>full post</content>

Back-End/Server Side General Logic

Now that you have the custom feed you can write the back-end code that will parse the custom XML and display blog content on your external website. I would suggest the logic be set up as follows:

  • Individual Post Display
    • Page that allows for a query string to pull in individual posts
    • Display the title, date, author and full post content
  • Listing Page Display
    • Page that pulls in a category listing (query string is optional)
    • Display title, date, author and teaser
    • Post titles would link to the individual post page with the specific post id as the query string parameter


If you follow this you can easily pull in your WordPress listings and individual posts via XML and your choice of back-end/server-side scripting language. This opens up a lot of possibilities for highly advanced and customized applications no matter what the platform.

Let's get to work!

Contact Us