how to load posts to a custom post template after using template_redirect or template_include

here is the full code to force change theme by a reserved wordpress parameter

add_action(
    'pre_get_posts',
    'my_pre_get_posts'
);

function my_pre_get_posts($wp_query) {
    global $wpdb;

    // Confirm request is main query
    if(!$wp_query->is_main_query()) {
        return;
    }

    // Get post name from query
    $post_name = $wp_query->get('pagename');

    // Get post type from database
    $post_type = $wpdb->get_var(
        $wpdb->prepare(
            'SELECT post_type FROM ' . $wpdb->posts . ' WHERE post_name = %s LIMIT 1',
            $post_name
        )
    );

    // Confirm page is post
    if ($post_type === 'post') {
        $wp_query->set('m', '');
    }
}

add_action(
    'template_redirect',
    'my_template_redirect'
);

function my_template_redirect() {
    global $post, $wp_query;

    if ($wp_query->query['m'] === '123') {
        include TEMPLATEPATH . '/template-name.php';
        die();
    }
}

you can also use the template include method instead of template_redirect hook as long as you add global $wp_query to your function