Get the selected term in a dropdown search

To show dropdown with currently selected option, first you need to fetch
current value. You can get that value from $_REQUEST variable. If you have grade variable then your current value is $_REQUEST[‘grade’].

Eg.
if ($_REQUEST['grade'] == $term->slug)

Recommended:
Do not use REQUEST variable directly without sanitization. Use function like esc_attr. If you are sure that you need positive integer, you can use absint.
May be.

$current_grade = esc_attr( $_REQUEST['grade'] );
if ($_REQUEST['grade'] == $term->slug)

Leave a Comment