Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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] => 
)
share|improve this question
1  
How are you looking at WP_Query and what do you see when the page loads? –  Greg Mar 23 '11 at 0:57
    
@Greg: Thanks for your answer. I updated the Q. When i load the page i see the empty WP_Query object (see above). Setup is a complete vanilla wp. –  kaiser Mar 23 '11 at 1:33
    
Ya know $wp_query usually has scope, you can generally just do this straight in your template files(global if inside a function) ... print_r( $wp_query ); .. –  t31os Mar 23 '11 at 11:53
add comment

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
    
Oh, haha! I was pretty confused looking at this. Yea... maybe i'm just too tired after a .5kg steak. Thanks, mister :) –  kaiser Mar 23 '11 at 1:50
    
Short Q (brain still not working). When should i trigger the function to show the query in the admin UI? Thanks. –  kaiser Mar 23 '11 at 2:31
1  
I use 'admin_notices'. –  scribu Mar 23 '11 at 13:30
    
thanks mate .. . –  kaiser Mar 23 '11 at 19:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.