0

Just testing this on a site and am having trouble with the path I think, (got it wokring on another site fine)

My function is here: domain.com/shop/library/smarty/plugins/function.recentposts.php

My Wordpress install: domain.com/wp/wp-load.php

The path in function file: ././././wp/wp-load.php

Looks ok to me

Im just getting call to undefined function error on screen. The only difference in each test site is the path and the fact that on this site I did the install in /wp/ but set the site to appear as if it is on the root, could that be it?

Zoe
  • 27,060
  • 21
  • 118
  • 148
john
  • 399
  • 1
  • 3
  • 9
  • ¿What's the function? Some accept absolute paths which makes it easy. But, yes, most probably the path is wrong because WP is installed in other directory. Try using `ABSPATH . 'wp-load.php'`, for example. But, again, that depends on the function. – Felipe Alameda A Jan 05 '13 at 18:11

1 Answers1

1

The following works for me in a file located at /root/path/test/test.php:

define( 'WP_USE_THEMES', false );
require( $_SERVER['DOCUMENT_ROOT'] . '/wp/wp-load.php' );

$recent_posts = wp_get_recent_posts();
var_dump( $recent_posts );

See: How to get the absolute path to the public_html folder?

Related Q&A at WordPress StackExchange: What is the best way to get directory path for wp-config.php?

Related blog post on how not to do it: wp-load.php – I Will Find You!

Community
  • 1
  • 1
brasofilo
  • 25,496
  • 15
  • 91
  • 179