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 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...)

<?php 
$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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.