I have a very strange problem that I am trying to troubleshoot:
I have a query (to build an array) that I run on a custom post type inside my plugin. It looks like this:
function makePointerQuery(){
//global $post;
$pqargs = array(
'post_type' => 'sbap_pointer',
'posts_per_page' => -1
);
$pointer_query = array();
$pp_query = get_posts($pqargs);
if ($pp_query) :
foreach ( $pp_query as $post ) : setup_postdata( $post );
$pointer_query[] = array(
'id' => get_post_meta($post->ID, '_sbap_pointerid_text', true ),
'screen' => get_post_meta($post->ID, '_sbap_screen_text', true ),
'title' => get_the_title($post->ID),
'content' => get_the_content($post->ID)
);
endforeach; endif;
wp_reset_postdata();
return $pointer_query;
}
If I leave out global $post, my plugin seems to function just fine, but I get the following PHP Notice (with debugging on):
Notice: Trying to get property of non-object in /wp-includes/post-template.php on line 289
BUT if I include global $post, while that notice goes away, something very strange happens. Every ("Add New") new post page ("post-new.php" in posts, pages, my custom post type, etc) is pulling up and filling out the data from my first custom post (ie the title, content, slug are all filled in with that post's data instead of the blank fields as would be normal for a new post).
I am at a loss as to how to eliminate that error notice while still having my plugin function as expected (without messing up every new post in admin).
Any ideas? Thanks in advance!