Question

I just realized, that i got a complete *empty WP_Query object* on my plain wordpress install. I reseted the DB, deactivated all plugins and activated TwentyTen as theme, but the complete Object simply is empty on every request (public & admin facing). It doesn't matter if i request the "Hello World" post or a 404. Everything is empty. What reason could this have?

Edit 1
This is how i inspect WP_Query:

// inserted on top of the functions.php file, 
// so it's equal to a function hooked into the 'after_setup_theme' hook  
// i also tried other hooks (which should make no difference) and got the same result.
    echo '<pre>'; 
        print_r($GLOBALS['wp_query']); 
    echo '</pre>';

This is the result from the print_r();

WP_Query Object
(
    [query] => 
    [query_vars] => Array
        (
        )

    [tax_query] => 
    [queried_object] => 
    [queried_object_id] => 
    [request] => 
    [posts] => 
    [post_count] => 0
    [current_post] => -1
    [in_the_loop] => 
    [post] => 
    [comments] => 
    [comment_count] => 0
    [current_comment] => -1
    [comment] => 
    [found_posts] => 0
    [max_num_pages] => 0
    [max_num_comment_pages] => 0
    [is_single] => 
    [is_preview] => 
    [is_page] => 
    [is_archive] => 
    [is_date] => 
    [is_year] => 
    [is_month] => 
    [is_day] => 
    [is_time] => 
    [is_author] => 
    [is_category] => 
    [is_tag] => 
    [is_tax] => 
    [is_search] => 
    [is_feed] => 
    [is_comment_feed] => 
    [is_trackback] => 
    [is_home] => 
    [is_404] => 
    [is_comments_popup] => 
    [is_paged] => 
    [is_admin] => 
    [is_attachment] => 
    [is_singular] => 
    [is_robots] => 
    [is_posts_page] => 
    [is_post_type_archive] => 
    [parsed_tax_query] => 
)
Was it helpful?

Solution

It's empty because you're looking at it before it has a chance to be populated.

The top of functions.php is too early. You should be doing it in a 'template_redirect' action.

Or, better yet, use the Debug Bar plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top