You could force WP’s hand here with a filter and action. Doing this doesn’t give me the warm fuzzies- I haven’t really tested it, so it may have unintended side-effects. Maybe there’s a better way to do this.
The first step (after setting permalinks to /%monthnum%/%day%/
) is to hook parse_query
and test for requests where monthnum
and day
are set. When that’s true, we unset some things and set some other things, to trick WP into thinking this is a singular post request. Maybe this will break other date archives, I didn’t test that!
function wpd_parse_query( $query ){
if( isset( $query->query_vars['monthnum'] )
&& isset( $query->query_vars['day'] )
&& 0 != $query->query_vars['monthnum'] ){
unset($query->is_archive);
unset($query->is_date);
unset($query->is_day);
$query->is_single = 1;
$query->is_singular = 1;
}
}
add_action( 'parse_query', 'wpd_parse_query' );
The next step is to filter post_limits
, and test for the unusual condition of it being a singular post with non-zero monthnum
. In this case we set it to return the first post, in the case that there’s more than one.
function wpd_post_limits( $limit, $query ) {
if( $query->is_main_query()
&& $query->is_singular()
&& isset( $query->query_vars['monthnum'] )
&& 0 != $query->query_vars['monthnum'] ){
return 'LIMIT 1';
}
return $limit;
}
add_filter( 'post_limits', 'wpd_post_limits', 10, 2 );
You could just leave that part out if you don’t care about that case- if the template uses The Loop, it will just repeat the contained markup for each post, though all other data outside the loop will refer to the first post- title, shortlink, body classes, etc..
Now these requests should be interpreted as singular posts, template tags should behave accordingly, and the single template will be loaded.