Title: Query_Posts and date function doesn&#039;t fork correctly
Last modified: August 20, 2016

---

# Query_Posts and date function doesn't fork correctly

 *  [LazySpidey](https://wordpress.org/support/users/lazyspidey/)
 * (@lazyspidey)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/)
 * Hi there..
 * I am trying to bring the posts for a specific date (I have more than for that
   day). I spent a lot of time in the forums and found some solutions.
 * The code below looks like working:
 *     ```
       <?php
       $current_year = date('Y');
       $current_month = date('m');
       $post_query = 'cat='.$cat1_id.'&posts_per_page=3&offset=1&year=$current_year&monthnum=$current_month&day=15';
       ?>
       <?php query_posts( $post_query ); ?>
       ```
   
 * But when i change **the specific day (19) with current day function, it fails
   to work:**
 *     ```
       <?php
       $current_year = date('Y');
       $current_month = date('m');
       $current_day = date('j');
       $post_query = 'cat='.$cat1_id.'&posts_per_page=3&offset=1&year=$current_year&monthnum=$current_month&day=$current_day';
       ?>
       <?php query_posts( $post_query ); ?>
       ```
   
 * I tried to debug and used `<?php echo $current_day; ?>` and it works flawlessly,
   shows the proper day (19).
 * I have to use the function to grab the current day… But somehow it does not work.
 * Do you have any idea about what i am missing?
 * Thx

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054709)
 * Try converting your date strings into integers.
 *  Thread Starter [LazySpidey](https://wordpress.org/support/users/lazyspidey/)
 * (@lazyspidey)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054712)
 * What do you mean by that?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054715)
 * caused by false php string and variable concatenation;
 * try:
 *     ```
       $post_query = 'cat='.$cat1_id.'&posts_per_page=3&offset=1&year='.$current_year.'&monthnum='.$current_month.'&day='.$current_day;
       ```
   
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054716)
 * The PHP date() function creates strings – not integers. According to the [Codex](http://codex.wordpress.org/Function_Reference/WP_Query#Time_Parameters),
   the time parameters in a custom query need to be integers.
 *  Thread Starter [LazySpidey](https://wordpress.org/support/users/lazyspidey/)
 * (@lazyspidey)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054718)
 * Wohooo!!! Thx alchymyth!!! Works like a charm..
 * For the ones who wants to query specific date (today’s) posts, can use the following
   code:
 *     ```
       <?php
       				$current_year = date('Y');
       				$current_month = date('m');
       				$current_day = date('j');
   
       $post_query = 'cat='.$cat1_id.'&posts_per_page=3&offset=1&year='.$current_year.'&monthnum='.$current_month.'&day='.$current_day;
       ?>
       				<?php query_posts( $post_query ); ?>
       ```
   
 * Thx again!!
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054724)
 * alternatively, check the Codex:
 * [http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters)
 * > **Returns posts for just the current date: **
   >     ```
   >     $today = getdate();
   >     $query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"] );
   >     ```
   > 
 *  Thread Starter [LazySpidey](https://wordpress.org/support/users/lazyspidey/)
 * (@lazyspidey)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054728)
 * OK.. But what about post after a specific date? Sould;
 * `$post_query = 'cat='.$cat1_id.'&posts_per_page=3&offset=1&year='.$current_year.'&
   monthnum='.$current_month.'&day>'.$current_day;`
 * work? (Noticed the “>” at the day variable?
 * Because it doesn’t 🙂
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054857)
 * > post after a specific date?
 * your example of ‘posts after today’ would ask for ‘scheduled’ or ‘future’ posts–
   this is a total different query, using the ‘post_status=future’ argument: [http://codex.wordpress.org/Class_Reference/WP_Query#Type_.26_Status_Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Type_.26_Status_Parameters)
 * for posts after a certain date in the past, you need to use a filter function;
   
   also from the [Codex ](http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters)(
   only minor adjustment):
 *     ```
       // Create a new filtering function that will add our where clause to the query
       function filter_where( $where = '' ) {
       	// posts for March 1 to March 15, 2010
       	$where .= " AND post_date >= '2010-03-01';
       	return $where;
       }
   
       add_filter( 'posts_where', 'filter_where' );
       $query = new WP_Query( $query_string );
       remove_filter( 'posts_where', 'filter_where' );
       ```
   
 *  Thread Starter [LazySpidey](https://wordpress.org/support/users/lazyspidey/)
 * (@lazyspidey)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054859)
 * I found an easier way (for me)..
 * I put this in the loop:
 *     ```
       <?php
       $postDateF = strtotime( $post->post_date );
       $todaysDateF = time() - (time() % 86400);
       if ( $postDateF >= $todaysDateF) : ?>
       ```
   
 * By this i can check if a post is today or after today 🙂
 * Problem solved.. Thx a lot..

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

The topic ‘Query_Posts and date function doesn't fork correctly’ is closed to new
replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 3 participants
 * Last reply from: [LazySpidey](https://wordpress.org/support/users/lazyspidey/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/query_posts-and-date-function-doesnt-fork-correctly/#post-3054859)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
