While using the WordPress Ajax API to query certain posts the content of WP_Query is always empty (that means the class exists but every property is set to null or false).

function my_ajax_admin() {
        $query = new WP_Query();
        $tab = array();


        while($query->have_posts()):
            // never reached
        endwhile;
        die(json_encode($out));
    }
}

Is it in general not possible to use WP_Query in Ajax called? May I load something into the function to make it work? Do I require additional parameters?

Read more here: Is instantiating WP_Query not possible within an admin Ajax call?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: