Skip to content

How to display posts outside of WordPress

Last updated on February 10, 2018

WordPress is built upon a collection of powerful core APIs. You can actually load the core APIs into any PHP application, just like any other library. It is quite simple to do, you need to include the file wp-load.php where ever you want to include the WP core API.

Assuming your blog is located in /user/var/www/html/blog, the single line below loads in WordPress API into your non-wordpress application.

require '/var/www/html/blog/wp-load.php';

Once the wp-load.php file is loaded into your code, you have access to the WP API. For instance, you can query the database for the recent blog posts, and display them where you did like show on your website.

// Include the wp-load.php
require '/var/www/html/blog/wp-load.php';
 
// Get the last 10 posts
// Returns posts as arrays instead of get_posts' objects
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 10
));
 
echo '';
0 0 votes
Article Rating
Subscribe
Notify of
guest

2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments