• 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)
Viewing 2 replies - 1 through 2 (of 2 total)

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