I am using wp_dropdown_categories within a form to perform a search that filters posts within a custom post type.
<form method="get" action="#anchor" id="findresult">
<?php wp_dropdown_categories('name=location&child_of=2'); ?>
<input id="submit" type="submit" value="SEARCH"/>
</form>
Once the form is submitted I would like the dropdown to retain the value that the user has selected.
Firstly I'm not sure from reading the documentation in the link below if this is even possible?
https://codex.wordpress.org/Function_Reference/wp_dropdown_categories
I know that upon submission I have the location id in the $GET array and I understand that I can get the name from this by using the below:
// Get id of category
<?php $locid = $_GET["location"]; ?>
//Get category name from id
<?php $locname = get_cat_name( $locid ) ?>
// Echo name to show it's working as expected
<h1><?php echo $locname; ?></h1>
What I don't know how to do is to set this as the 'value' of the dropdown after the form has been submitted.
All time and help is greatly appreciated.