I require to retrieve a list of the recently created blog posts or any Query-based usage of WP posts inside my PHP website and not within WP framework.

I am new to Wordpress and stucked here. I already tried with include wp-includes/post.php file but i guess its still not working. Facing error regarding undefined constant and function. I don't know whether I am correct or not here. Is there any way to resolve this?

  • "This is really urgent for me to accomplish." is not really a matter here. For more info see How to Ask. Also, please use the search, the question has been answered several times already. If you find something, then please cast a close vote on your question to close it as duplicate. Thanks in advance.
    – kaiser
    Nov 26, 2015 at 10:46

3 Answers 3


It's just simple, same reply from Error in WP_update_post but in your case there is small change.

Just use wp-load.php as include. No need to include post.php. Once the wp-load.php file is included, the entire wealth of WordPress functions is provided to you.

For pull the recent post, you need to use wp_get_recent_posts() wordpress function which is from WP framework.

So your PHP code will like:


// Include the wp-load'

// For example get the last 10 posts

// Returns posts as arrays instead of get_posts' objects
$recent_posts = wp_get_recent_posts(array(
    'numberposts' => 10


Let me know if there is any doubt/query from this.


I require to retrieve a list of the recently created blog posts

  1. Connect to WP database (name/user/pass can be fount in wp-config.php) and
  2. execute SQL query same as with any other DB

This link will help you to find your way around easier. https://codex.wordpress.org/Database_Description

That of course presuming you know php, not just what few WP functions does...

  • Thanks for your prompt response. I really appreciate this, but i don't think this resolves my purpose. I require solution in context with error I am facing.
    – DSmith
    Nov 26, 2015 at 11:42
  • You probably getting error due usage of functions that are not defined. But I'm guessing. Can you provide code sample? Nov 26, 2015 at 11:45

Apart from BozidarS's and AddWeb Solution Pvt Ltd's solutions which are both good, if you want to access your WP from another domain you will probabbly want to use one of the WordPress API's. There are two good plugins that provide JSON REST API's:

I personally prefer the latter, as WP-REST-API currently has a bug with the post__in filter (if you only want a specific list of ids you only have two options: get them one by one (multiple api calls) or get all unpaginated posts and filter out the results; another workaround for this bug is to create categories based on your REST needs and request posts by category).

However, word is out that WP-REST-API might become the "official" REST api for WordPress, but I don't have a reliable source to backup this statement. It's just hearsay.

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.