Title: Problem using query_posts()
Last modified: August 19, 2016

---

# Problem using query_posts()

 *  [Ski Freak](https://wordpress.org/support/users/ski-freak/)
 * (@ski-freak)
 * [15 years ago](https://wordpress.org/support/topic/problem-using-query_posts/)
 * Below is the code I am using.
    The problem I am getting is that the date call
   in the second block does not return any data. Can anyone tell what I am doing
   wrong?
 *     ```
       <?php  query_posts('posts_per_page=1&category_name=Cat1'); ?>
       <?php  if (have_posts()) : the_post(); ?>
       	<div class="widget latest-post">
       		<span class="latest-title">Latest Cat 1 Post</span><br />
       		<span class="date"><?php the_date(); ?></span><br />
       		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       		<?php the_excerpt(); ?>
       	</div> <!-- END Latest Posts -->
       <?php
       	endif;
       	wp_reset_query();
       ?>
   
       <?php  query_posts('posts_per_page=1&category_name=Cat2'); ?>
       <?php  if (have_posts()) : the_post(); ?>
       	<div class="widget latest-post">
       		<span class="latest-title">Latest Cat 2 Post</span><br />
       		<span class="date"><?php the_date(); ?></span><br />
       		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       		<?php the_excerpt(); ?>
       	</div> <!-- END Latest Posts -->
       <?php
       	endif;
       	wp_reset_query();
       ?>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years ago](https://wordpress.org/support/topic/problem-using-query_posts/#post-2052817)
 * > that the date call in the second block does not return any data.
 * this is one of the peculiarities of `the_date()` as explained in here:
 * [http://codex.wordpress.org/Function_Reference/the_date](http://codex.wordpress.org/Function_Reference/the_date)
 *  Thread Starter [Ski Freak](https://wordpress.org/support/users/ski-freak/)
 * (@ski-freak)
 * [15 years ago](https://wordpress.org/support/topic/problem-using-query_posts/#post-2052824)
 * Thanks for the quick response…
 * I have tried, and failed, using get_the_date()
    How would I use this in the code
   above?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years ago](https://wordpress.org/support/topic/problem-using-query_posts/#post-2052825)
 * i would try to replace:
    `<?php the_date(); ?>` with `<?php echo get_the_date();?
   >`
 *  Thread Starter [Ski Freak](https://wordpress.org/support/users/ski-freak/)
 * (@ski-freak)
 * [15 years ago](https://wordpress.org/support/topic/problem-using-query_posts/#post-2052830)
 * Thanks for the suggestion but that does not cater for the dates of the posts 
   being different.
    The code below works, but this is ugly code as far as I am 
   concerned. I am open to suggestions for a better way of doing this. First block:`
   <span class="date"><?php $postDate = the_date(); ?></span><br />` Second block:`
   <span class="date"><?php echo ($postDate == "") ? get_the_date(): the_date();?
   ></span><br />`

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Problem using query_posts()’ is closed to new replies.

## Tags

 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [Ski Freak](https://wordpress.org/support/users/ski-freak/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/problem-using-query_posts/#post-2052830)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
