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?
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:
or a cleaner method would be to use short hand notation