开发者

Wordpress query in CodeIgniter model

I have the following method in a CI model:

function getPostTitle($post_slug)
{
 global $post;
 $posts = new WP_Query('name=' . $post_slug);

 while ( $posts->have_posts() ) 
    { 
   $posts->the_post();
   return $post->post_name;
 }
}

The returned variable is empty. Note that the same code works fine in a view. I need to be able to use the above query in a model so that is available to开发者_JS百科 the controller. Any Wordpress/Codeigniter experts?


I wonder if this quote from the philplmieri.com link you supplied is a key to the answer:

"all the functions are available to you in your templates and views in ci.."

Maybe all WordPress functions aren't available in controllers and models, only views.

Another avenue is to test whether get_posts() works in the model instead of WP_Query().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜