zardon
zardon

Reputation: 2920

Wordpress - How do I output the last query used by query_posts?

I am attempting to grab all posts for a specific day (ie: today), however for some reason it is only returning the one.

$wp_posts = query_posts(array(
            'cat' => 4,
            'post_status' => array('any', 'publish', 'future', 'inherit', 'revision', 'pending'), 
            'year' => '2011',
            'monthnum' => '10',
            'day' => '25',                  
            'order_by' => 'post_date',
            'order' => 'ASC'
            ));

This should post all the posts for today under a category, but whatever reason it only outputs 1 post and I do not know why.

At first I thought it might be a permalink issue, but I removed the permalinks and its still only returning the one post?

On my localhost the code works fine and outputs all the content required for a specific day.

Additionally, I have checked the database and all the posts for the day are there and appear to be in schedule or posted status.

So there is no reason why the query_posts should be returning just 1 item.

I want to output the last query used by query_posts to investigate what is causing the problem.

How do I verbosely output the last query as used by query_posts?

Thanks.

Edit.

I will accept an answer that converts the above to a verbose SQL query which I can run to see what is going on

Upvotes: 3

Views: 8326

Answers (3)

Stefan
Stefan

Reputation: 1284

the last query is always stored in $wpdb->last_query and for post queries as well in $wp_query->request

Upvotes: 0

zardon
zardon

Reputation: 2920

I figured out what the problem was.

On http://codex.wordpress.org/Custom_Queries it seems to imply that a post_limit has a default.

I successfully outputted the entire object using a blank page and combining WP_Query with my posts array posted above.

In it I found a response with a limit of 0,1

I'm not sure why it put this in, or why it only affected my live site.

But this seems to correspond with the limit I noted in the Custom_Queries code.

In my file, I put this:

add_filter('post_limits', 'gloss_limits' );

function gloss_limits( )
{
     return "";
}

As per the Custom_Queries URL.

And it removed the limit and I finally got to output everything from that day.

I've accepted Jorbin's answer as the 'Save queries for analysis' is a specific answer to my query.

Upvotes: 0

Jorbin
Jorbin

Reputation: 171

Take a look at http://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis (please make sure you take note of the warning to not do this on a production site).

The solution is that you probably need to set the posts_per_page value in your arguments array to -1.

Upvotes: 1

Related Questions