Title: Show post when between two dates
Last modified: August 22, 2016

---

# Show post when between two dates

 *  [Anouk](https://wordpress.org/support/users/anouk0693/)
 * (@anouk0693)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/show-post-when-between-two-dates/)
 * Hi everyone!
 * I’ve made (with Advanced Custom Fields) a date picker where you can choose from
   which to which date you want to show a post on the site. For example I want a
   post to show from 01-01-2014 to 01-01-2015 and after the last date the post won’t
   be shown anymore.
 * I’ve found a hack with the where filter, but I can’t seem to figure out how to
   use that function with variables.
 *     ```
       <?php
       // WP_Query arguments
       $args = array (
       	'post_type'              => 'vacature',
       	'pagination'             => false,
       	'posts_per_page'         => '3',
       );
   
       $start = get_field('online_vanaf');
       $end = get_field('online_tot');
   
       function filter_where( $where = '' ) {
   
       global $start;
       global $end;
   
       $where .= " AND post_date >= '$start' AND post_date < '$end'";
       return $where;
       }
   
       add_filter( 'posts_where', 'filter_where' );
   
       $vacatures = new WP_Query( $args );
   
       // The Loop
       if ( $vacatures->have_posts() ) {
       	while ( $vacatures->have_posts() ) {
       		$vacatures->the_post();
   
       ?>
       ```
   
 * You can see my code above. I don’t get an error, WordPress just won’t show the
   posts anymore..
    Any help is welcome!
 * Thanks in advance.

The topic ‘Show post when between two dates’ is closed to new replies.

## Tags

 * [act](https://wordpress.org/support/topic-tag/act/)
 * [between](https://wordpress.org/support/topic-tag/between/)
 * [date](https://wordpress.org/support/topic-tag/date/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * 0 replies
 * 1 participant
 * Last reply from: [Anouk](https://wordpress.org/support/users/anouk0693/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/show-post-when-between-two-dates/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
