WordPress.org

Ready to get started?Download WordPress

Forums

WP_Query in plugin defaults author to current user (2 posts)

  1. boland
    Member
    Posted 11 months ago #

    I am working on a plugin and encountered something strange. I create a new WP_Query and pass some arguments, including "author"=> NULL, but the query returns with [query_vars][author] => 10 (or whatever the ID of the current non-admin user is). Consequentially, the posts returned all belong to the current user.

    Has anyone else ever experienced this?

    add_filter('views_edit-post', array(&$this,'fix_post_counts'));
    
    	public function fix_post_counts($views) {
    	    global $current_user, $posts, $wp_query;
    	    $result = new WP_Query(array(
    	    		"post_status" => NULL,
    	    		"posts_per_page" => -1,
    	    		"author" => NULL,
    	    ));
    	    print_r($result); //Returns with author set
           }

    Unfortunately, this is all running local, so no link just yet.

  2. esmi
    Forum Moderator
    Posted 11 months ago #

    Why specify "author" => NULL? I don't think you can use null as a value with WP_Query parameters.

Reply

You must log in to post.

About this Topic