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

I have a Custom template with a custom query. I want to use additional information about the current taxonomy > description and name (and use it in the HEAD, desc, keywords, etc...)

$productvariable = $_GET['product'];

$term = get_term_by('slug', $productvariable, 'mytaxonomy');
$mytitle = $term->name;
$mydesc = $term->description;
  • How do i make the variable safe from url to get_term_by ($value)?
  • And what if there is no match is it possible to use ELSE?
  • Is it possible to use the values inside HEAD (header.php)?

Is there a security issue when using a GET variable from url with get_term_by?

share|improve this question
up vote 1 down vote accepted

you can look at line 874 in /wp-includes/taxonomy.php for the function itself. the value has stripslashes applied and then it's used in a prepared statement, so I'd say it's safe. but there's nothing stopping you from checking the value yourself first if you know what parameters it will always fall within, like ctype_alnum or something. then check if(empty($term)), to see if anything matched and print something else if not.

share|improve this answer

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.