Searchform.php re-configuration.

Hi! On my front page i have created a series of dropdown menus for category selection. However, when i click the search button, the results won't show up at all. It identifies the correct category, but fails to collect the posts related to that category.

The search can be found here:
stilius.se/wilink

This is my javascript code in header.php:

<script type='text/javascript'>
var lanSelectBox;
var stadSelectBox;
var branschSelectBox;

function prepareSearch()
{
lanSelectBox = document.getElementById("lanSelectBox");
stadSelectBox = document.getElementById("stadSelectBox");
branschSelectBox = document.getElementById("branschSelectBox");

lanSelectBox.onchange = onLanChanged;
stadSelectBox.onchange = onStadChanged;
branschSelectBox.onchange = onBranschChanged;
}

function onLanChanged()
{
var lan = lanSelectBox.options[lanSelectBox.selectedIndex].value;
if(lan != -1) document.location.href = "?lan="+lan;
}

function onStadChanged()
{
var lan = lanSelectBox.options[lanSelectBox.selectedIndex].value;
var stad = stadSelectBox.options[stadSelectBox.selectedIndex].value;

if(stad != -1)
{
if(lan != -1)
{
document.location.href = "?lan=" + lan + "&stad=" + stad;
}
else
{
document.location.href = "?stad=" + stad;
}
}
else
{
if(lan != -1)
{
document.location.href = "?lan=" + lan;
}
}
}

function onBranschChanged()
{
var bransch = branschSelectBox.options[branschSelectBox.selectedIndex].value;
}
</script>

And this is my php code in searchform.php:

<form action="<?php echo home_url( '/' ); ?>" method="get" id="searchform" >

<?php
$selectedLan = 0;
if(isset($_GET["lan"])) $selectedLan = $_GET["lan"];
$lan = array(
'show_option_all' => '',
'show_option_none' => 'Län',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 1,
'child_of' => 0,
'exclude' => '',
'echo' => 1,
'selected' => $selectedLan,
'hierarchical' => 1,
'name' => 'cat',
'id' => 'lanSelectBox',
'class' => 'postform',
'depth' => 1,
'tab_index' => 0,
'taxonomy' => 'product_category',
'hide_if_empty' => false
);

$id = 0;
if(isset($_GET["lan"]))
{
$id = $_GET["lan"];

}
$selectedStad = 0;
if(isset($_GET["stad"])) $selectedStad = $_GET["stad"];

$stad = array(
'show_option_all' => '',
'show_option_none' => 'Stad',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 1,
'child_of' => $id,
'exclude' => '1,16,21,22',
'echo' => 1,
'selected' => $selectedStad,
'hierarchical' => 0,
'name' => 'cat',
'id' => 'stadSelectBox',
'class' => 'postform',
'depth' => 0,
'tab_index' => 0,
'taxonomy' => 'product_category',
'hide_if_empty' => false
);

$id = 0;
if(isset($_GET["stad"]))
{
$id = $_GET["stad"];
}
$selectedBransch= 0;
if(isset($_GET["bransch"])) $selectedBransch= $_GET["bransch"];

$bransch = array(
'show_option_all' => '',
'show_option_none' => 'Bransch',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 1,
'child_of' => $id,
'exclude' => '1,16,17,20',
'echo' => 1,
'selected' => $selectedBransch,
'hierarchical' => 0,
'name' => 'cat',
'id' => 'branschSelectBox',
'class' => 'postform',
'depth' => 0,
'tab_index' => 0,
'taxonomy' => 'product_category',
'hide_if_empty' => false
);
?>

<?php wp_dropdown_categories( $lan ); ?>
<?php
wp_dropdown_categories( $stad );
wp_dropdown_categories( $bransch);
?>

<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Sök', TEMPLATE_DOMAIN ); ?>" />

</form>

Do I need to change anything in this file, or perhaps category.php or search.php?

  • aecnu

    Greetings Stilius,

    Thank you for bringing this to our attention but custom coding is beyond the scope of the support that we provide here and I do not have a lead developer/coder assigned to custom coding though we do try to help if we can.

    With that said if you cannot custom code this in yourself alternatively you could see if there's a developer available at wpmu jobs who could get onto it right this minute or perhaps tweaky.com can custom code the solution in for you.

    Thank you for being a WPMU DEV Community Member!

    Cheers, Joe

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.