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?


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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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