Add pages to home / front page recent posts loop

Mods and Stuff for WordPress
Post Reply
User avatar
syntax
Site Admin
Posts: 54
Joined: Tue Jan 06, 2009 9:25 pm

Add pages to home / front page recent posts loop

Post by syntax » Wed Dec 17, 2014 6:05 pm

Using a second function I limit the pages to only pages that are less than 1 month old (published date). You can change the date or comment it out to modify.

Code: Select all

//add pages to home page
add_filter( 'pre_get_posts', 'asd_add_pages' );
function asd_add_pages( $query ) {

	if ( is_front_page() && $query->is_main_query() ) {
		$query->set( 'post_type', array( 'post', 'page' ) );
		add_filter( 'posts_where', 'asd_add_pages_where' );
	}
	return $query;
}
function asd_add_pages_where( $where = '' ) {
    $before_date = date( 'Y-m-d', strtotime("-1 month") );
    $where .= " AND (`post_date` > '".$before_date."' OR `post_type` != 'page')";
    return $where;
}

Post Reply