• Resolved Iurie Malai

    (@flegmatiq)


    I think that the locations will be more optimal to show in a drop-down list, with a possibility to select multiple locations. In this way, if there are registered many locations, users will not be required to guess what locations exists in the database.

    An additional feature will be the possibility to search with some keywords in a few selected locations.

    https://www.ads-software.com/plugins/wpadverts/

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

    (@gwin)

    I will think about it, but to be honest right now i am not really planning to change how the locations work.

    That being said you can paste the code below in your theme functions.php or even better create new WP plugin and paste it there it will convert location field to dropdown, you just need some basic PHP knowledge to fill options

    add_filter("adverts_form_load", "locations_to_dropdown");
    function locations_to_dropdown( $form ) {
        if($form["name"] != "advert") {
            return $form;
        }
    
        foreach($form["field"] as $k => $field) {
            if($field["name"] == "adverts_location") {
                $field["type"] = "adverts_field_select";
                $field["max_choices"] = 1;
                $field["options"] = array(
                    array("value" => "New York", "text" => "New York", "depth" => 0),
                    array("value" => "Chicago", "text" => "Chicago", "depth" => 0),
                    // more options here
                );
    
                $form["field"][$k] = $field;
                break;
            }
        }
    
        return $form;
    }
    Thread Starter Iurie Malai

    (@flegmatiq)

    Thank you, Greg! I will try this solution.

    Regards, Iurie

    Thread Starter Iurie Malai

    (@flegmatiq)

    Hi Greg,

    Today I wanted to test the above function, but I discovered that I was not very clear in my first message. Sorry! What I had in mind was a drop down list for locations in the search form, on the main Adverts page. Of course, I also like a drop down list in the Add new advert page, that works very well.

    Regards,
    Iurie

    Plugin Author Greg Winiarski

    (@gwin)

    Hi, the locations input in the search form you can turn into dropdown only by modifying wpadverts/templates/index.php file as right now there are no hooks to do it.

    Thread Starter Iurie Malai

    (@flegmatiq)

    In the wpadverts/templates/ does not exists an index.php file.

    Maybe list.php?

    Plugin Author Greg Winiarski

    (@gwin)

    Yes, it should be list.php

    In list, what should be changed to reflect the dropdown on the search page?

    Plugin Author Greg Winiarski

    (@gwin)

    You need to replace <input type="text" name="location" placeholder="<?php _e("Location ...", "adverts") ?>" value="<?php esc_attr_e($location) ?>" /> with <select> field, but note this does require some HTML / PHP knowledge.

    Thread Starter Iurie Malai

    (@flegmatiq)

    Thanks, Greg! I wanted to ask myself this.

    Thank you Greg. I tried to do this based on the exact code you gave above for changing the field on the add listing page but could not get the dropdown to appear on the front search page.

    I replaced that line with the select field but it does not seem to be working. Do you know what the new code should look like?

    Plugin Author Greg Winiarski

    (@gwin)

    The code i pasted is not exact, like i wrote earlier it will require some PHP / HTML knowledge to replace it, the code will be something like this.

    <select name="location">
        <option value=""></option>
        <option value="London">London</option>
        <!-- more options here -->
    </select>
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Locations in a drop-down list’ is closed to new replies.