Reodering search parameters in link

Screenshot Search Form

I’m trying to implement a custom search with php and wordpress. The search will be able to crawl through the post objects. According to the radio inputs the search should filter post after the custom taxonomy “kursart”. Then we have the search input which should search after the keyword. I also need a dropdown which includes the “kursmethode” which is saved inside a meta field with the key “kursmethode”.

My form will look like that:

And this is my code till now:

function startkurs(){

          // Erzeuge Form für die Ausgabe im Frontend
    ?>

    <div class="container">
        <form class="form cf search-input-form" method="get" action="<?php echo get_site_url(); ?>"  id="form-all">
            <section class="plan cf">
                <input type="radio" name="kursart" id="alle-kurse" value="alle-kurse"><label class="free-label four col" for="alle-kurse">Alle Kurse</label>
                <input type="radio" name="kursart" id="studiengaenge" value="studiengaenge" checked><label class="basic-label four col" for="studiengaenge">Studiengänge</label>
                <input type="radio" name="kursart" id="ausbildung" value="ausbildung"><label class="premium-label four col" for="ausbildung">Ausbildung</label>
                <input type="radio" name="kursart" id="seminare" value="seminare"><label class="test-label four col" for="seminare">Semiare</label>
            </section>

            <div class="lil-spacer"></div>

                              <div class="form_inputs" style="width: 83%;">

                    <input type="text" name="s" size="30" value="<?php the_search_query(); ?>" placeholder="Finden Sie Ihren Kurs ..." class="text-search" />

                    <select class="btn-methodik" name="methode">
                        <option value="all" selected > -- Auswählen -- </option>
                        <option value="Präsenzveranstaltung">Präsenzveranstaltung</option>
                        <option value="Online">Online</option>
                        <option value="Fernunterricht">Fernunterricht</option>
                        <option value="Blended">Blended</option>
                        <option value="Inhouse">Inhouse</option>
                    </select>

                              </div>

                              <button type="submit" name="fulltext" class="btn-search" form="form-all" value="Suchen">Suchen</button >


        </form>

        <!-- button type="submit" name="fulltext" class="btn-search" form="form-all" value="Suchen">Suchen</button -->

        <?php
        $search_field = $_GET['s']; // get the search input
        $my_select_taxonomy = $_GET['methode']; // get the selected value

                    $args = array(
                              's' => $search_field,
                              'post_type' => 'post', // Search in Posts
                              'post_per_page' => 10, // Display 10 Posts
                              'orderby'=> 'title', // Order Results after their title
                              'order' => 'DESC', // order in descending order
                              'meta_key' => 'kursmethode', // search inside the selected meta field
                              'meta_value' => $my_select_taxonomy, // search inside the meta field according to the selected value
                              'meta_compare' => 'LIKE', // only show results that equal the selected term
                    );


                    $radio = isset($_POST['kursart']);
                    switch ($radio){
                              case 'alle-kurse':
                                        $args = array(
                        's' => $search_field,
                        'post_type' => 'post', // Search in Posts
                        'post_per_page' => 10, // Display 10 Posts
                        'orderby'=> 'title', // Order Results after their title
                        'order' => 'DESC', // order in descending order
                        'meta_key' => 'kursmethode', // search inside the selected meta field
                        'meta_value' => $my_select_taxonomy, // search inside the meta field according to the selected value
                        'meta_compare' => 'LIKE', // only show results that equal the selected term
                    );
                                        break;
                              case 'studiengaenge':
                                        $args = array(
                        's' => $search_field,
                        'post_type' => 'post', // Search in Posts
                        'post_per_page' => 10, // Display 10 Posts
                        'orderby'=> 'title', // Order Results after their title
                        'order' => 'DESC', // order in descending order
                        'meta_key' => 'kursmethode', // search inside the selected meta field
                        'meta_value' => $my_select_taxonomy, // search inside the meta field according to the selected value
                        'meta_compare' => 'LIKE', // only show results that equal the selected term
                        // 'tax_query' => array(
                        //  array(
                        //      'taxonomy' => 'kursart',
                        //      'field'    => 'term_id',
                        //      'terms'    => array( 609,620,621,622 ),
                        //      'operator' => 'IN'
                        //  ),
                        // ),

                    );
                                        break;
                              case 'ausbildung':
                                        $args = array(
                        's' => $search_field,
                        'post_type' => 'post', // Search in Posts
                        'post_per_page' => 10, // Display 10 Posts
                        'orderby'=> 'title', // Order Results after their title
                        'order' => 'DESC', // order in descending order
                        'category__in' => '608',
                        'meta_key' => 'kursmethode', // search inside the selected meta field
                        'meta_value' => $my_select_taxonomy, // search inside the meta field according to the selected value
                        'meta_compare' => 'LIKE', // only show results that equal the selected term
                        // 'tax_query' => array(
                        //  array(
                        //      'taxonomy' => 'kursart',
                        //      'field'    => 'term_id',
                        //      'terms'    => array( 608 ),
                        //      'operator' => 'IN'
                        //  ),
                        // ),
                    );
                                        break;
                              case 'seminare':
                                        $args = array(
                        's' => $search_field,
                        'post_type' => 'post', // Search in Posts
                        'post_per_page' => 10, // Display 10 Posts
                        'orderby'=> 'title', // Order Results after their title
                        'order' => 'DESC', // order in descending order
                        'meta_key' => 'kursmethode', // search inside the selected meta field
                        'meta_value' => $my_select_taxonomy, // search inside the meta field according to the selected value
                        'meta_compare' => 'LIKE', // only show results that equal the selected term
                        // 'tax_query' => array(
                        //  array(
                        //      'taxonomy' => 'kursart',
                        //      'field'    => 'term_id',
                        //      'terms'    => array( 606,614,610,611,615,612,613 ),
                        //      'operator' => 'IN'
                        //  ),
                        // ),
                    );
                                        break;

                    }





        $query = new WP_Query( $args );

        ?>

    </div>

    <?php
}

add_shortcode('TEST', 'startkurs');

It produces a link like that:

http://mydomain.de/?kursart=alle-kurse&s=content&methode=all&fulltext=Suchen

But i need the link to look like that to get the search results on the according page:

http://mydomain.de/?s=content&kursart=alle-kurse&s=content&methode=all

I dont understand what i’m doing wrong here.
I appriciate your help

Read more here:: Reodering search parameters in link

Leave a Reply

Your email address will not be published. Required fields are marked *