WordPress.org

Ready to get started?Download WordPress

Forums

Virtual Page Within Theme Template (2 posts)

  1. edrdesign
    Member
    Posted 1 year ago #

    I am creating a plugin that needs a virtual page in order to dynamically create an "Review Order" page. I was able to create a virtual page using the following code:

    // Set up the rewrite rules for the order page
    add_action( 'init', 'action_init_redirect' );
    function action_init_redirect() {
    add_rewrite_rule( 'orders/?', 'index.php?orders=new', 'top' );
    }

    add_filter( 'query_vars', 'filter_query_vars' );
    function filter_query_vars( $query_vars ) {
    $query_vars[] = 'orders';
    return $query_vars;
    }

    add_action( 'parse_request', 'action_parse_request');
    function action_parse_request( &$wp ) {
    if ( array_key_exists( 'orders', $wp->query_vars ) ) {
    echo "hello";
    exit;
    }
    }

    The problem is that this creates a page with a blank template, that is, the above code creates a blank page with the text "hello". I would like for the virtual page to be within the theme of the site and displayed like a regular page within the WordPress framework. How is the best way to accomplish this?

  2. bcworkz
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic