4

I currently have the following query:

$args = array(
              'post_type' => 'post',
              'orderby'   => 'title',
              'order'     => 'ASC',
              'posts_per_page' => 10,
            );

$my_query = new WP_Query($args);

while ($my_query->have_posts()) : $my_query->the_post(); ?>

This returns all the posts that are published. How can I alter it to show every post whether it's published, pending, or in draft?

12

You can add post_status to your query, the string 'any' will return all posts no matter the status, or you can use an array to just grab those you want.

$args = array(
              'post_type' => 'post',
              'orderby'   => 'title',
              'order'     => 'ASC',
              'post_status' => 'any',
              'posts_per_page' => 10,
            );

http://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters

2

Also you can customize for pending and drafts or any selected status

$args = array(
              'post_type' => 'post',
              'orderby'   => 'title',
              'order'     => 'ASC',
              'post_status' => array( 'pending', 'draft', 'future' ),
              'posts_per_page' => 10,
            );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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