Allows WP_Query to use a 'since' argument to query for relative date queries using `strtotime()`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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