WordPress Query Object Properties

This is an example dump of the $wp_query object

Here is the code snippet I used to create this. I unset all the post data with the two unset commands.

global $wp_query;
$forReturn .= $wp_query->found_posts;
$temp = clone $wp_query;
unset($temp->post);
unset($temp->posts);
$forReturn .= print_r($temp, true);

Some of the items you’ll notice you can get to include WordPress’ Found Posts:

$wp_query->found_posts

$wp_query->post_count

$wp_query->query

WP_Query Object
(
    [query_vars] => Array
        (
            [cat] => 5
            [showposts] =>
            [count] =>
            [post_status] => publish,private,future
            [error] =>
            [m] => 0
            [p] => 0
            [post_parent] =>
            [subpost] =>
            [subpost_id] =>
            [attachment] =>
            [attachment_id] => 0
            [name] =>
            [hour] =>
            [static] =>
            [pagename] =>
            [page_id] => 0
            [second] =>
            [minute] =>
            [day] => 0
            [monthnum] => 0
            [year] => 0
            [w] => 0
            [category_name] =>
            [tag] =>
            [tag_id] => 0
            [author_name] =>
            [feed] =>
            [tb] =>
            [paged] => 0
            [comments_popup] =>
            [meta_key] =>
            [meta_value] =>
            [preview] =>
            [category__in] => Array
                (
                    [0] => 5
                )

            [category__not_in] => Array
                (
                )

            [category__and] => Array
                (
                )

            [post__in] => Array
                (
                )

            [post__not_in] => Array
                (
                )

            [tag__in] => Array
                (
                )

            [tag__not_in] => Array
                (
                )

            [tag__and] => Array
                (
                )

            [tag_slug__in] => Array
                (
                )

            [tag_slug__and] => Array
                (
                )

            [caller_get_posts] =>
            [suppress_filters] =>
            [post_type] => post
            [posts_per_page] => 10
            [nopaging] =>
            [comments_per_page] => 50
            [order] => DESC
            [orderby] => wp_posts.post_date DESC
        )

    [request] =>  SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)  WHERE 1=1  AND wp_term_taxonomy.taxonomy = 'category'  AND wp_term_taxonomy.term_id IN ('5')  AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'future' OR wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND post_date < NOW() /* HERE 1 */  GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
    [post_count] => 10
    [current_post] => -1
    [in_the_loop] =>
    [comments] =>
    [comment_count] => 0
    [current_comment] => -1
    [comment] =>
    [found_posts] => 10
    [max_num_pages] => 1
    [max_num_comment_pages] => 0
    [is_single] =>
    [is_preview] =>
    [is_page] =>
    [is_archive] => 1
    [is_date] =>
    [is_year] =>
    [is_month] =>
    [is_day] =>
    [is_time] =>
    [is_author] =>
    [is_category] => 1
    [is_tag] =>
    [is_tax] =>
    [is_search] =>
    [is_feed] =>
    [is_comment_feed] =>
    [is_trackback] =>
    [is_home] =>
    [is_404] =>
    [is_comments_popup] =>
    [is_admin] =>
    [is_attachment] =>
    [is_singular] =>
    [is_robots] =>
    [is_posts_page] =>
    [is_paged] =>
    [query] => cat=5&showposts=&count&post_status=publish,private,future
)

Related Posts:

  • No Related Posts
This entry was posted in Web Development. Bookmark the permalink.

3 Responses to WordPress Query Object Properties

  1. @rrs_atl says:

    Great Post! It helped me out

  2. Dan Gayle says:

    Nice. I’ve needed this twice in the past month :)

  3. People usually create by far the most useful reports. Also , you usually often receive bad/boring issues and switch these folks in to exciting/interesting issues. Internet marketing your viewer for lifetime!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>