WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Just looking for some advice on something that is bugging me. Please bear in mind I am a PHP noob :-)

I am passing a variable in the url to my WP index page like so:

<a href="<?php bloginfo('url');?>/?do=thing">Thing</a>

I am the catching that variable, and using it to show content like so:

<?php $do_that = $_GET["do"]; if($do_that == 'thing') : ?> etc

Naturally I am getting debug errors when the variable is not passed :-)

"Undefined index: do"

My question is what am I missing wrong? Obvious I spose?

Also is this bad practice?

share|improve this question
up vote 2 down vote accepted

The error is occurring as the $_GET array doesn't have the item $_GET['do'] in it. Therefore it throws this notice. To check if something exisits in the array try:

if( isset( $_GET['do'] ) )
   $do_that = $_GET['do'];
   $do_that = '';

or a cleaner method would be to use short hand notation

$do_that = ( isset( $_GET['do'] ) ) ? $_GET['do'] : '';
share|improve this answer
You will still need to validate the data, remember to NEVER trust a users input. Check out the article codex.wordpress.org/Data_Validation there are some great helper functions that can clean the data :) – Cristian Jul 18 '11 at 12:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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