Title: Troubleshoot [query_posts]
Last modified: August 19, 2016

---

# Troubleshoot [query_posts]

 *  [eons](https://wordpress.org/support/users/eons/)
 * (@eons)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/troubleshoot-query_posts/)
 * I’m assigning 2 custom fields to all my post,start_date and end_date.
    Right 
   now in my main page, i would like to display all the posts which fall between
   the 2 date. Seems like not post show up after few trials. Hope someone will assist
   me here… Thanks.
 * >  <?php
   >  function filter_where($where = ”) { global $wpdb; $cur_date = date(‘
   > Ymd’); $where .= ” ‘{$cur_date}’ >= (SELECT meta_value FROM {$wpdb->postmeta}
   > WHERE meta_key = ‘start_date’ AND post_id = {$wpdb->posts}.ID)”; $where .= ”
   > AND ‘{$cur_date}’ <= (SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key
   > = ‘end_date’ AND post_id = {$wpdb->posts}.ID)”; return $where; }
   > function filter_join($join = ”) {
   >  global $wpdb; $join .= ” INNER JOIN {$wpdb-
   > >postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id”; return $join;}
   > add_filter(‘posts_where’, ‘filter_where’);
   >  add_filter(‘posts_join’, ‘filter_join’);
   > query_posts($query_string); ?>

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

 *  Thread Starter [eons](https://wordpress.org/support/users/eons/)
 * (@eons)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/troubleshoot-query_posts/#post-1635066)
 * anyone can help?
 *  Thread Starter [eons](https://wordpress.org/support/users/eons/)
 * (@eons)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/troubleshoot-query_posts/#post-1635187)
 * Any guru can advise?

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

The topic ‘Troubleshoot [query_posts]’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [eons](https://wordpress.org/support/users/eons/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/troubleshoot-query_posts/#post-1635187)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
