views:

22

answers:

1

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 the controller. Any Wordpress/Codeigniter experts?

A: 

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().

kevtrout
Thanks, I haven't noticed that. No query function works in controllers/models, although other functions seem to work, for example: get_the_category(), get_tags().
Zack
I found two links on the topic of integragrating CI and WP:http://jidd.jimisaacs.com/archives/892/ and http://stackoverflow.com/questions/1253906/how-to-integrate-wordpress-template-with-codeigniter
kevtrout