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:
/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!
For everything wordpress that is accessed outside wordpress system, you HAVE to include
wp-load.php
I think @silent means that you need to have both included for it to work. I however need both when I’m running WordPress.
Take a look at this http://www.webopius.com/content/139/using-the-wordpress-api-from-pages-outside-of-wordpress
Apparently adding:
right before:
does the trick.