0

I have a custom post type which has a custom taxonomy called "Financial Sector".

I am trying to display a select box on the home page of my site so that users can select a Financial Sector and it takes you to that page.

Here is the code I am using to populate the select box.

<form class="fin-form-select" action="<?php bloginfo('url'); ?>/"    method="get">

<label for="choose-fin">Search by Product.</label>

<?php
$select = wp_dropdown_categories(
'taxonomy=financial-  sector
&name=financial-sector
&show_option_all=Please    Choose...
&show_count=0
&orderby=name
&order=ASC
&echo=0
');

$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>

<noscript><input class="rtd-btn primary" type="submit" value="View" />  </noscript>
</form>

The problem I am having is that when you choose a selection, the link goes to a 404 page. I have flushed the permalinks and still no joy.

Can anybody supply me with a fix or a better way of achieving my goal.

Thanks

Dan

0

Here is the answer I was looking for. Staring me right in the face.

I have managed to fix this issue with a simple addition to the code.

&value_field=slug

So final code which works and maybe of help in the future.

<form action="<?php bloginfo('url'); ?>/" method="get">
<label for="">Search.</label>

<?php
$select = wp_dropdown_categories(
'taxonomy=YOURTAXONOMY
&name=YOURTAXONOMY
&show_option_all=Please Choose...
&show_count=0
&orderby=name
&order=ASC
&echo=0
');

$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return     this.form.submit()'>", $select);
echo $select;
?>

<noscript><input class="rtd-btn primary" type="submit" value="View" />    </noscript>
</form>

Just change YOURTAXONOMY with your custom-taxonomy slug.

Hope this helps.

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