Allows WP_Query to use a 'since' argument to query for relative date queries using `strtotime()`
<?php | |
/** | |
* Allows WP_Query to use a 'since' argument to query for | |
* relative date queries. | |
* | |
* Usage: Query posts from last 30 days | |
* $query = new WP_Query('since' => '-30 days'); | |
* | |
* @uses strtotime() | |
* @author Eddie Moya | |
**/ | |
function filter_where_add_since( $where = '', $query) { | |
if( isset($query->query_vars['since']) ){ | |
$where .= " AND post_date > '" . date('Y-m-d', strtotime($query->query_vars['since'])) . "'"; | |
} | |
return $where; | |
} | |
add_filter( 'posts_where', 'filter_where_add_since', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment