Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to use the get_option() function of wordpress in one of my theme's files, which is not related to WP, it is just located in the same directory of the other theme files. I need this file because of some extra IPN paypal related actions, but I need some values from the options table that exists in WP to be called in this page in order for it to work. I know I can't just use get_option() as this file is overlooked by wordpress. Is there any approach by including some parts of wordpress in my theme to make this functionality only work?

share|improve this question
    
I retagged your question. Hint: Just take a look inside wp-load.php. –  kaiser Oct 14 '12 at 19:40
add comment

3 Answers

Turn your external file into a WordPress plugin. That way you'll have full access to WP core functions.

share|improve this answer
1  
This would make your life much easier in the long run. –  westondeboer Oct 14 '12 at 17:31
add comment

The simplest way is include wp-load.php file. This file will loads all WP core, so you can use WP functions such as get_option in your PHP file:

include 'path/to/wp-load.php';

echo get_option( 'option_name' );
share|improve this answer
    
+1 But by above answer, you can delete "the simplest" ;) –  kaiser Oct 14 '12 at 19:48
1  
One line (including wp-load.php) vs. multiple lines (plugin comments in the beginning), that's the simplest, lol. –  Rilwis Oct 15 '12 at 1:16
add comment

The shortest way is to load wp-load.php and abort the loading of the template engine (Note: You couldn't do that, if you'd be loading the header file, like you see it on many sites in the interweb).

# No need for the template engine
define( 'WP_USE_THEMES', false );
# Load WordPress Core
// Assuming we're in a subdir: "~/wp-content/plugins/current_dir"
require_once( '../../../wp-load.php' );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.