I need to get posts from a certain timeframe.
I am using the posts_where
filter.
I want to specify a beginning date and an end date. This is the function I use:
function filter_where( $where = '' ) {
$where .= " AND post_date >= '2012-03-01' AND post_date =< '2014-03-01'";
return $where;
}
This Filter returns nothing. The error ust be located anywhere around the second AND
.
This is my function:
number_sold_mottos( $from, $till );
function number_sold_mottos( $from, $till ){
add_filter( 'posts_where', 'filter_where' );
$args = array( 'posts_per_page' => -1, 'post_type' => 'shop_order' );
$post_ids = array();
$the_query = new WP_Query( $args );
$last_order_ids = array();
if ( $the_query -> have_posts() ):
while ( $the_query -> have_posts()) :
$the_query -> the_post();
the_title();
endwhile;
endif;
wp_reset_query();
remove_filter( 'posts_where', 'filter_where' );
}
function filter_where( $where ) {
$where .= " AND post_date >= '2012-03-01' AND post_date =< '2014-03-01'";
return $where;
}
Any help is welcome.
=<
operator doen't exists in MySQL, the right operator for 'lower-or-equal-to' is<=