So pre_get_posts
seems to be the way to do this now - a lot of the background is nicely explained here: When to use WP_query(), query_posts() and pre_get_posts
I can happily modify the main loop to show a chosen month using this function:
function loop_current_month( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'monthnum', 3 );
return;
}
}
add_action( 'pre_get_posts', 'loop_current_month' );
However, I would like to modify the loop for the current month, and the current year.
How can $query->set()
take two vars? Something like:
$query->set( 'monthnum', 3 & 'year', 2013 );
Any ideas?
Many thanks Dave