You can do it easily with WP_Query
:
$args = array(
'date_query' => array(
'relation' => 'OR',
array(
'column' => 'post_date',
'after' => '-2 days'
),
array(
'column' => 'post_modified',
'after' => '-2 days'
)
)
);
$query = new WP_Query( $args );
More information about date_query
parameter of WP_Query
.
If, for some reason, you still want to alter the WHERE
clausele, something like this should work (not tested):
function filter_where($where="") {
$where .= " AND ( post_date > '" . date('Y-m-d', strtotime('-2 days')) . " OR post_modified > " . date('Y-m-d', strtotime('-2 days')) . " )'";
return $where;
}
add_filter('posts_where', 'filter_where');
Also, you must note that in the post where filter, you are using Y-m-d
date format, which doesn’t include time. That can cause unexpected results; you may need to use MySQL datetime format: Y-m-d H:i:s
.