Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi, i am not sure, it seems that the same query works if you reverse params https://bizzakat.my/bizzakat-my-hasil-carian/?ad_category=29&location=69, is there any plugin installed on your site that might be conflicting with WPAdverts?

    Thread Starter zul

    (@ae98)

    Search result shows all categories in selected location. It suppose only show results on selected category from selected location.

    For example, I select location id 71 and category id 35. But, result shows all categories from location id 71.

    Plugin Author Greg Winiarski

    (@gwin)

    Sorry, i can’t really replicate this issue on my dev site, like i wrote earlier you can disale plugins one by one and see if the problems goes away.

    You can also use debug bar plugin and check what actual MySQL query is being executed, with your search params it should be something like

    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND (
    wp_term_relationships.term_taxonomy_id IN (35)
    ) AND (
    ( wp_postmeta.meta_key = 'adverts_location' AND CAST(wp_postmeta.meta_value AS CHAR) LIKE '%71%' )
    ) AND wp_posts.post_type = 'advert' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.menu_order DESC, wp_posts.post_date DESC LIMIT 0, 20

    Also one strange thing about your query is that your search by category param is ad_category, by default (withe the code snippet i am sharing on GitHub) it should be advert_category.

    Thread Starter zul

    (@ae98)

    I have tried to disable all plugins except Wp Adverts and Wp Adverts – Maps and Locations, also changing search param to advert_category. Still got no solution.

    I also execute MySQL query using suggested plugins, and it show no result either from debug bar nor phpmyadmin.

    Try run link here
    This link suppose to show 6 results. But, it show all results from location id 76 (Pekan) and not only by category id 35 (Peralatan). AURA TIMUR is not from category id 35.

    Thread Starter zul

    (@ae98)

    I have do some try and error. Changing Location Field search in WPAdverts setting, using search location other than Use Default will cause an error.

    Dropdown, autocomplete and Google autocomplete option will produce the error.

    Plugin Author Greg Winiarski

    (@gwin)

    Can you paste a screenshot with your Maps and Locations settings?

    Also, how do you have the location field converted into dropdown, with MAL add-on it should be either text box or multiselect dropdown, but on your site it is single select dropdown, are you using some custom code for this?

    Thread Starter zul

    (@ae98)

    Here is the screenshot image https://postimg.org/image/ewge7ramt/

    I’m using code combined from your documentation and support.

    add_filter( 'adverts_form_load', 'location_to_dropdown' );
    
    function location_to_dropdown( $form ) {
    
      if( $form['name'] != 'search' ) {
        return $form;
      }
    
      foreach( $form["field"] as $key => $field ) {
        if( $field["name"] == "location" ) {
          $field["type"] = "adverts_field_select";
          $field["empty_option"] = 1;
          $field["empty_option_text"] = "Seluruh Pahang";
          $field["options"] = array(
            array("value" => "Bentong", "text" => "Bentong"),
            array("value" => "Bera", "text" => "Bera"),
            array("value" => "Cameron Highlands", "text" => "Cameron Highlands"),
            array("value" => "Chenor", "text" => "Chenor"),
            array("value" => "Jengka", "text" => "Jengka"),
            array("value" => "Jerantut", "text" => "Jerantut"),
            array("value" => "Kuantan", "text" => "Kuantan"),
            array("value" => "Kuala Lipis", "text" => "Lipis"),
            array("value" => "Maran", "text" => "Maran"),
            array("value" => "Muadzam Shah", "text" => "Muadzam Shah"),
            array("value" => "Pekan", "text" => "Pekan"),
            array("value" => "Raub", "text" => "Raub"),
            array("value" => "Rompin", "text" => "Rompin"),
            array("value" => "Temerloh", "text" => "Temerloh"),
            // more options here
          );
          $form["field"][$key] = $field;
        }
      }
    
      return $form;
    }
    Plugin Author Greg Winiarski

    (@gwin)

    Note that if you are using MAL add-on you should not use any other code to modify the location field in a search form, you should only use the options provided by MAL otherwise, you might get unexpected results, as MAL modifies how data is stored in DB and applies some filters to fine tune the search.

    Thread Starter zul

    (@ae98)

    I have also tried to delete the line of code but, the output still same. By the way, modifying multiple select into single select location solve this problem.

    Thanks for the help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Location search not working with category search’ is closed to new replies.