I am having trouble accessing the post variable outside the loop.
My plugin code is as follows:
global $wp_query; // trying to make any variable I have found reference to be involved in $post global so it can be accessed global $post; global $posts;
2) I have included code with the output I have found using xdebug. Nothing I have tried has allowed me to access the $post object. Can you give me any advice on how to do this.
Vladimir’s WordPress Forum
Accessing $POST object within plugin
23:11
13 October, 2010
KC
Hello,
I am having trouble accessing the post variable outside the loop.
My plugin code is as follows:
global $wp_query; // trying to make any variable I have found reference to be involved in $post global so it can be accessed
global $post;
global $posts;
echo $post->post_content; // returns nothing
add_filter( 'the_content', ds_add_to_content);
echo get_the_content() . "hello"; //returns hello
var_dump($post); // returns null
echo ($post->post_content); // returns nothing
My questions:
1) Is a plugin considered part of the loop?
2) I have included code with the output I have found using xdebug. Nothing I have tried has allowed me to access the $post object. Can you give me any advice on how to do this.
Thanks again in advance,
KC: