最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

api - Call WordPress function outside of WordPress

programmeradmin3浏览0评论

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();
发布评论

评论列表(0)

  1. 暂无评论