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'm trying to create an archive page that grabs every post submitted. At the moment, I have this, which doesn't work:

<?php

   $args = array ();
   $query = new WP_Query( $args );

if ( $query->have_posts() ) {
  while ( $query->have_posts() ) {
    $query->the_post();?>

        <div class="post">


<?php first_item() ?>



<?php
  }
} else {
  // no posts found
}

// Restore original Post Data
wp_reset_postdata(); ?>

However, if I change the array to:

   $args = array (
  'tag'                 => 'films',
);

It starts receiving all posts tagged as films.

How come this is only working with tagged posts, and not for every post?

I do have a loop on the front page and on custom page, so could they be conflicting?

share|improve this question
1  
Your code is not complete, I guess. Where do you close div.post? What does first_item() do exactly? –  t f Dec 20 '13 at 10:48

1 Answer 1

You've given WP_Query and empty argument set, effectively asking it to get "nothing". Try:

$args = array ();
$query = new WP_Query( $args );
var_dump($query);

As soon as you give it something to latch onto, like your tag argument, the query works. To get all of your posts pass a post_type argument.

$args = array ('post_type'=>'post');
$query = new wp_query( $args );
var_dump($query);

Or to get all post types...

$args = array ('post_type'=>'any');
$query = new wp_query( $args );
var_dump($query);

Or to only get particular post types...

$args = array ('post_type'=> array('post','book'));
$query = new wp_query( $args );
var_dump($query);
share|improve this answer

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.