Skip to content

Instantly share code, notes, and snippets.

@nucab
Forked from corsonr/gist:4648007
Last active August 29, 2015 14:21
Show Gist options
  • Save nucab/7fd1503ab8ce69f3c3c0 to your computer and use it in GitHub Desktop.
Save nucab/7fd1503ab8ce69f3c3c0 to your computer and use it in GitHub Desktop.
<?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