I am writing an script to get WordPress posts and user data outside WordPress files and folder, this script run by side of WordPress installation but will fetch data from WordPress as explained below.
1. Created a file showmydata.php in WordPress root folder.
2. place require( '../wp-load.php' );
in file to use WordPress function.
3. write class and functions in showmydata.php to show details to users
now i am facing problem to call WordPress function inside class. how can I use query_posts and others inside class.
following is my class structure.
require( '../wp-load.php' );
class MyData {
public $data = "";
public function __construct(){
parent::__construct();
$this->get_posts();
}
function get_posts(){
query_posts(array('showposts'=> -1,'post_type'=>'coupon'));
while(have_posts()): the_post();
the_title();
endwhile;
}
}
$api = new MyData;
$api->get_posts();