For me I’d used a little different approach:
- use an endpoint to create an url like
http://example.com/no-formats/
- hooking
pre_get_posts
to set the proper query if needed - filter
template_include
to force WP to usehome.php
instead of duplicating it
No more.
add_action('init', 'add_no_format_endpoint');
function add_no_format_endpoint() {
add_rewrite_endpoint( 'no-formats', EP_ROOT );
}
add_action('pre_get_posts', 'handle_no_format');
function handle_no_format( $q ) {
if ( $q->is_main_query() && is_home() && isset( $q->query['no-formats'] ) ) {
unset( $q->query['no-formats'] );
$q->is_home = FALSE; // <- add this if you have setted a static page as frontpage
$tax_q = array(
'taxonomy' => 'post_format',
'field' => 'id',
'operator' => 'NOT IN',
'terms' => get_terms( 'post_format', array( 'fields' => 'ids' ) )
);
$q->set( 'tax_query', array( $tax_q) );
add_filter( 'template_include', 'force_home_template', 999 );
}
}
function force_home_template() {
return locate_template( array( 'home.php', 'index.php' ), FALSE );
}
Remember to visit Settings->Permalinks in you dashboard to flush rewrite rules.