Query posts published after a certain date in Wordpress
wordpress
Solution
The "Time Parameters" section in http://codex.wordpress.org/Class_Reference/WP_Query has a note about date ranges. Using the same technique:
$query_string = "order=ASC&posts_per_page=-1";
// Create a new filtering function that will add our where clause to the query
function filter_where( $where = '' ) {
$where .= " AND post_date >= '2012-03-01'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$custom_query = new WP_Query( $query_string );
remove_filter( 'posts_where', 'filter_where' );
Problem
I'm trying to write a `WP_Query` where I'm calling only posts that have been posted after march 2012. I can successfully call posts that are just in March 2012, but struggling to do 'from March 2012 onwards'. ``` $current_year = date('2012'); $current_month = date('>3'); // This doesn't work $current_month = date('3'); // This DOES work $custom_query = new WP_Query("year=$current_year&monthnum=$current_month&order=ASC&posts_per_page=-1"); ``` Am I missing something simple, or does this have to get more complicated?