-
-
Save nucab/7fd1503ab8ce69f3c3c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// Load our function when hook is set | |
add_action( 'pre_get_posts', 'rc_modify_query_get_posts_by_date' ); | |
// Modify the current query | |
function rc_modify_query_get_posts_older_than_today( $query ) { | |
// Check if on frontend and main query is modified | |
if( ! is_admin() && $query->is_main_query() ) { | |
$query->set( 'order', 'ASC' ); | |
add_filter( 'posts_where', 'rc_filter_where' ); | |
} | |
return $query; | |
} | |
// Filter posts older than today | |
function rc_filter_where( $where = '' ) { | |
$today = date( 'Y-m-d' ); | |
$where .= " AND post_date >= '$today'"; | |
return $where; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment