• Resolved David Gard

    (@duck_boy)


    Hey all,

    Using query_posts();, does anybody know of a way to get posts that are less than 6 months old?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter David Gard

    (@duck_boy)

    Thanks for the reply. I did have a look at where you suggested before hand, but I couldn’t make a workable example.

    I did however just find this and it works perfectly –

    add_filter('posts_where', 'filter_where');
    /**
     * Adds a date range to the WHERE portion of our query
     *
     * @param string $where The current WHERE portion of the query
     * @return string $where The updated WHERE portion of the query
     */
    function filter_where($where = ''){
        $where .= " AND post_date > '".date('Y-m-d', strtotime('-180 days'))."'";
        return $where;
    }

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts less than 6 months old’ is closed to new replies.