How to create a dynamic page based on form data with a plugin?

Something like this should work, though I’m not sure how meta, title, etc.. will behave, you’ll want to test everything thoroughly!

function my_template_redirect() {
    global $wp;
    $qvs = $wp->query_vars;
    if (array_key_exists( 'laundry', $qvs && $qvs['laundry'] == 'thank-you' ) {
        global $wp_query;
        $wp_query->set( 'is_404', false );
        // ... now what?

        $post = new stdClass();
        $post->ID= -99; // fake ID, hehe
        $post->post_content="some content";
        $post->post_excerpt="an excerpt";
        $post->post_status="publish";
        $post->post_title="My fake page";
        $post->post_type="page";
        $wp_query->queried_object = $post;
        $wp_query->post = $post;
        $wp_query->found_posts = 1;
        $wp_query->post_count = 1;
        $wp_query->max_num_pages = 1;
        $wp_query->is_page = 1;
        $wp_query->is_404 = false;
        $wp_query->posts = array($post);
        $wp_query->page = 1;
        $wp_query->is_post = false;

    }
}

Leave a Comment