Accesing WordPress API within my PHP app

I’m accessing the WordPress API from within my PHP code just including the wp-blog-header.php and using get_posts().

This is working ok when my PHP code is at the same level than the WP directory. For example:

Read More
/blog/[..wp files..]
/index.php

At index.php, I have:

require('blog/wp-blog-header.php');
$post = get_posts(...);

and is working pretty well.

BUT, when I try to do the same with the code inside a directory, for example:

/blog/[..wp files..]
/folder/index.php

and at folder/index.php I have:

require('../blog/wp-blog-header.php');
$post = get_posts(...);

this always makes my app to redirect to the WP installation (wp-admin/install.php) and doesn’t work.

Any idea ? Can the API be used from within a directory ?

The blog is configured correctly and is working ok by itself.


Edit: Stack trace showing when the app redirects to wp_not_installed() when used inside a folder

6   0.4052  3402748 require_once( '/usr/www/juanjo/NuevaWebJuanjo/blog/wp-load.php' )   ../class_wordpress.php:11
7   0.4054  3408296 require_once( '/usr/www/juanjo/NuevaWebJuanjo/blog/wp-config.php' ) ../wp-load.php:30
8   0.4063  3487064 require_once( '/usr/www/juanjo/NuevaWebJuanjo/blog/wp-settings.php' )   ../wp-config.php:19
9   1.3650  6103276 wp_not_installed( ) ../wp-settings.php:100
10  1.6258  7676148 wp_redirect( )  ../load.php:408
11  1.6261  7684480 header ( )  ../pluggable.php:890

Thanks!

Related posts

Leave a Reply

3 comments

  1. For everything wordpress that is accessed outside wordpress system, you HAVE to include wp-load.php

    include("/absolute/path/to/wp-load.php");
    //do whatever you want