2

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!

2
  • Edited the question to add a stack trace when the require() fail and redirect to wp_not_installed(); Commented Oct 26, 2011 at 9:14
  • @ Juanjico - did you get anywhere with this issue, I have exactly the same problem Commented Dec 9, 2011 at 8:16

3 Answers 3

0

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
Sign up to request clarification or add additional context in comments.

2 Comments

This is even worse. If I replace require('blog/wp-blog-header.php'); by require('blog/wp-load.php'); it always call wp_not_installed() not matter if my app is in the root or inside a folder. Thanks anyway.
please, can you just try in any of your projects to include WP from within a folder? Just create a folder, put an index.php with the include() and see if you got redirected to the install ? I don't know if the problem is the WP itself (bad configuration) or what. Thanks.
0

I think @silent means that you need to have both included for it to work. I however need both when I'm running WordPress.

1 Comment

If I just do require('blog/wp-blog-header.php'); redirects to wp_not_installed() (when used inside a folder, not in root). If I just do require('blog/wp-load.php'); redirect to wp_not_installed() to (inside a folder or in root). So, it's impossible to include both, because the first redirects to wp_not_installed() and never execute the second require().
0

Take a look at this http://www.webopius.com/content/139/using-the-wordpress-api-from-pages-outside-of-wordpress

Apparently adding:

define('WP_USE_THEMES', false);

right before:

require('blog/wp-blog-header.php');

does the trick.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.