• sacconi

    (@sacconi)


    I’d like to add in my custom search box “Cerca e Filtra”, on the top of the right sidebar, some check boxes to add filtering criteria by tags; I installed search and filter plug-in free version, you can see at the bottom of the right-sidebar what I want to add to my top search box, is there a way to get usefull code by exploring this free plug-in files and “get inspiration” about coding? I could paste the code on pastebin

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You could copy the form’s HTML and use it in your form.

    As for handling the form’s submission, it looks like it just requests URLs like /tag/term1+term2+term3/. That might be OK for tag only filtering, but your search form involves other criteria, so I don’t think what the plugin does will be that useful for you.

    Staying with the idea of fixing queries through “pre_get_posts”, you will want to take the submitted tag data and create an array of values for one of the *__in or *__and tag args. ( __in is for OR logic, __and is for AND logic)

    Your form keeps getting more and more complicated. ?? It could get complex enough that all the data could go beyond URL length limitations. I recommend switching the form to POST method. In your related search form PHP, if you’ve been using $__REQUEST to get form data, nothing needs to change. But if you use $__GET, all instances of it need to change to either $__POST or $__REQUEST.

    If nothing else, the search results URL will be much cleaner with POST ?? It’s also better for user privacy FWIW. URL data is never encrypted, even over HTTPS. POST data over HTTPS is encrypted.

    Thread Starter sacconi

    (@sacconi)

    I would work about it, about the lenght of the query, in my current website I have long queries such as https://www.sacconicase.it/search.php?search=1&lang=it&sel_country=2&sel_region=16&sel_city=23&adv_fromsea=%3C+301&adv_min_pers=4&adv_max_pers=9999&period_from=&period_to=&adv_bathrooms=&adv_fromcenter=&adv_wash=checkbox&adv_barb=checkbox&adv_dish=checkbox&adv_tv=checkbox&adv_internet=checkbox&adv_animals=&adv_pool=&ava=1

    it’s not a good job or technically susteinable? A long search query address need a particular configuration on the server? I’d like if possible to keep all the work I’ve done up to now about the search box function

    I found an article: https://stackoverflow.com/questions/34182874/create-a-checkbox-for-tags-in-wordpress

    It can help for my work?

    Thread Starter sacconi

    (@sacconi)

    How can modify this

    //filtra con tags
    
    $post_tags = get_the_tags();
    $array = array(
        129 => array(
            'id' => '210',
            'name' => 'animali permessi su richiesta'
        ),
        130 => array(
            'id' => '216',
            'name' => 'aria condizionata'
        ),
        131 => array(
            'id' => '224',
            'name' => 'barbecue'
        )
    );
    // Iterate over the array
    foreach ($array as $c) {
        // Access the required data
        $id = $c['id'];
        $name = $c['name'];
    
        // Generate your checkbox
        print "<input type='checkbox' name='$name' id='$id'>";
    }
    
    

    In the output I’d put $post_tags

    First I have to generate the tags and their checkbox, then adding a search function, maybe adding a variable in the filter I already have:

    add_action( 'pre_get_posts', 'bedrooms_guests_search_query');
    
    function bedrooms_guests_search_query( $query ) {
       if (! is_admin() && $query->is_main_query()) {
          if ( array_key_exists('function_camere', $_GET ) &&
          
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding check boxes to filter by tags’ is closed to new replies.