I have a plugin that I'm writing. In the plugin I have the following class:
class aks_gf_augmentation {
public function __construct() {
$zip_code = '02653'; //this is temporary, eventually to be set by field filled out in gravity form
$query = new WP_Query( array(
'post_type' => 'aks_zip_code',
'name' => $zip_code
) );
if( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$rep_to_send = get_post_meta( $post->ID, 'aks_target', true );
}
}
else {
$rep_to_send = 'default@domain.com';
}
add_filter("gform_pre_send_email", "before_email");
function before_email($email){
global $rep_to_send;
$email["to"] = $rep_to_send;
return $email;
}
}
}
$aks_gf_augmentation = new aks_gf_augmentation;
The use of the 'post_type' argument in WP_Query throws this error:
Fatal error: Call to undefined function get_userdata() in /nas/wp/www/staging/agmoil/wp-includes/query.php on line 3911
If I remove the 'post_type' => 'amgo_zip_code' argument, the plugin doesn't return the correct post but it also doesn't thrown an error.
Am I missing something? I've never seen this error arise from using WP_Query in a plugin. Also I have double and triple checked that the name of the custom_post_type does = aks_zip_code
Any help would be greatly appreciated