I have a small problem that probably has a very simple fix. I have been using the wp_get_archives()
function to produce a dropdown select form. See the full code below:
<form id="side-arch">
<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
<?php wp_get_archives( array( 'type' => 'monthly', 'format' => 'option', 'show_post_count' => 1 ) ); ?>
</select>
<input type="submit" value="Go" id="submit" />
</form>
I would like to make this use the submit button, instead of the onchange event to execute the action. Obviously, what I should do is remove the onchange
element and add a form action. I have tried formatting it just like my functional category dropdown, which would achieve it by doing this:
<form id="side-arch" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
<select name="archive-dropdown">
<option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
<?php wp_get_archives( array( 'type' => 'monthly', 'format' => 'option', 'show_post_count' => 1 ) ); ?>
</select>
<input type="submit" value="Go" id="submit" />
</form>
However, this does not work. I am guessing that there is something wrong with the url in the form action, as it just sends me to the home page of the site.
Anyone have any ideas on how to switch this over to using a Go
button?