• Resolved Jesse Friedman

    (@professor44)


    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 = '[email protected]';
    		}
    
    		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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Jesse Friedman

    (@professor44)

    Also, I just figured out that the error only occurs when it actually finds a post and attempts to return it. If I alter any of the arguments to ensure no posts are queried, then no errors occur.

    Thread Starter Jesse Friedman

    (@professor44)

    I hate post midnight stupid mistakes.

    a.k.a. don’t leave functions like that in the __construct…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_Query in plugin throwing error’ is closed to new replies.