Tuesday 10 March 2015

How do I get wordpress global variable and functions in custom file [SOLVED]

How do I get wordpress global variable and functions in custom file


Problem:
I have create a file i.e mytestfile.php in root folder of wordpress blog.
Full path of mytestfile.php is http://www.example.com/blog/mytestfile.php.
Now, I want to access all global variables, functions like $wp_query, query_posts.



Solution:
As you have created mytestfile.php in blog root folder.
Just add the following line in top. This will load wordpress blog and you can access global variables.
require( 'wp-load.php' );
global $wp_query;
Now, you can access $wp_query, query_posts.