Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm currently trying to use a $_GET to populate a MySQL query with in a URL on another page within a Wordpress site.

URL sample:

<a href="http://site.com/file.php?alabama">Alabama</a>

MySQL Query sample:

$query = "select items from table_name where state = '$_GET[state]';

Which will then query the database based off the state name and then spit out an array with the data, etc.

I'm kinda of confused on how to get it with the permalinks kicked on.

I was reading this: Using $_GET variables in the URL?

But I'm not sure if that's the best way to do it (since there was a couple of examples) or if there is another recommendation? And I'm also not too sure how to get that to pass within the query string either?

share|improve this question
I hope your MySQL query example is a simpliflied version, as that line leaves you wide open for SQL injections. –  vancoder Apr 3 '13 at 17:47
I can't help 100% as I'm busy, but personally I'd set the '$_GET[state]' in a php variable BEFORE building the query. –  Michael Roach Apr 3 '13 at 17:47
@vancoder - Um, no...not really. I'm working on a previous project that was done before me. –  ultraloveninja Apr 3 '13 at 17:59
xkcd.com/327 is a classic example of what can happen if you don't escape the user input ;-) You should check out $wpdb->prepare() here: codex.wordpress.org/Class_Reference/… –  birgire Apr 3 '13 at 18:06
@vancoder - Ooooh. yeah. Man, it's been so long since I've had to build out a query by hand and I've forgotten about the escape string. –  ultraloveninja Apr 3 '13 at 18:14

Your Answer


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

Browse other questions tagged or ask your own question.