Support » Plugin: Relevanssi - A Better Search » add SELECT in searchform.php

  • Hi, I’m trying to change the searchform adding select tags.
    In my theme if i search “a b c” the search result in the url is “/?s=a+b+c”, but with the new form I am not able to print the sum.

    How can i solve?

    This is the code:

    <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
    <label>
    <select name="s" id="s">
    <option value="nessuno">choose</option>
    <option value="a">a</option>
    <option value="b">b</option>
    <option value="c">c</option>
    </select>
    </label>
    <label>
    <select name="s" id="s">
    <option value="nessuno">choose</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    </label>
    <label>
    <input type="submit" id="searchsubmit" value="Search" />
    </label>
    </form>

    https://wordpress.org/plugins/relevanssi/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Now that’s just not going to work like that. You can’t have multiple fields with the same name and id.

    You need to have different names for the fields and then add a pre_get_posts filter function where you combine the different fields to a one ‘s’ field.

    can you help me to write the pre_get_posts filter to add to function.php?

    Plugin Author Mikko Saari

    (@msaari)

    Unfortunately, no. I have to focus my support efforts on paying Relevanssi Premium customers.

    It’s not that difficult, though – the function needs to read the query variables from $wp_query->query_vars and combine them into $wp_query->query_vars[‘s’]. Not a bad little programming excercise…

    ok.
    i wrote the php, i think it’s:

    if (!empty($_GET[‘s’])) {
    $array = $_GET[‘s’];
    $result = “”;
    foreach ($array as $key => $value) {
    $result .= $value . ” “;
    }
    echo $result;
    }

    now maybe i have to put it in the:

    function add_query_vars_filter( $vars ){
    $vars[] = “my_var”;
    return $vars;
    }
    add_filter( ‘query_vars’, ‘add_query_vars_filter’ );

    is it right?

    Plugin Author Mikko Saari

    (@msaari)

    No, that code is just reading $_GET[‘s’]. You need to put the different parts of it in different variables with different names, then combine to $_GET[‘s’].

    dodoland, did you get this working? I am looking for the same thing.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘add SELECT in searchform.php’ is closed to new replies.