I have created a new 'page template' and (this is probably not the right way to do this, but this is the way I have got it working), and created a new page using that template. Within the page template (PHP file) I have made, I have put lots of PHP which makes the page function, like it has a simple login an view information from a SQL table.

The problem is, I need to be able to send $_GET data to the page. I can send POST fine, but not GET, and I dont know what the URL is.

For example, I would like to have clean URLs (that is what I have set wordpress to)



The name of the page template is teaching-portal, and I would like to get mygetdata into PHP. But currently anything passed after teaching-portal results in a 404 page.

How can i achieve this?


Assuming you have a page with the slug "teaching-portal", this plugin adds a rewrite rule for that page that allows one part to be added after it in the URL, what you refer to as "mygetdata". I've called it "lesson".

 * Plugin Name: Custom PHP app on teaching-portal page
 * Plugin URI: http://wordpress.stackexchange.com/questions/75991

// Flush rewrite rules on plugin activation
register_activation_hook(__FILE__, 'wpse75991_activate');
function wpse75991_activate()

// Flush rewrite rules on plugin deactivation
register_deactivation_hook(__FILE__, 'wpse75991_deactivate');
function wpse75991_deactivate()

// Add a custom rewrite rule for the teaching portal section
add_action('init', 'wpse75991_add_rewrite_rule');
function wpse75991_add_rewrite_rule()
    $pagename = 'teaching-portal'; // Slug

// Register the custom query var so WP recognizes it
add_filter('query_vars', 'wpse75991_add_query_var');
function wpse75991_add_query_var($vars)
    $vars[] = 'lesson';
    return $vars;

With this plugin activated you should be able to access the lesson variable in your page template. Here's a quick example:

$lesson = get_query_var('lesson');

if (empty($lesson))
    // Show all lessons
    // Show a single lesson

Also see the Rewrite API in the codex.

  • Wow, very amazing. That's really helpful, thank you so much.
    – Chud37
    Dec 13 '12 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.