Hi,
yes, you can do that either with the Custom Fields extension https://wpadverts.com/extensions/custom-fields/ or via the API.
For example, adding the code below in your theme functions.php file should do that, just update in the code the list of locations with your own locations.
add_filter( "adverts_form_load", "adverts_add_location_to_dropdown" );
function adverts_add_location_to_dropdown( $form ) {
if( $form['name'] == "advert" ) {
$field_name = "adverts_location";
} else if( $form['name'] == "search" ) {
$field_name = "location";
} else {
return $form;
}
foreach( $form["field"] as $key => $field ) {
if( $field["name"] == $field_name ) {
$form["field"][$key]["type"] = "adverts_field_select";
$form["field"][$key]["empty_option"] = true;
$form["field"][$key]["options"] = array(
array( "value" => "London", "text" => "London" ),
array( "value" => "New York", "text" => "New York" ),
/// more options here ...
);
}
}
return $form;
}
That is great thank you very much.
Im thinking about the future so i might buy the plugin also…
Where does the placeholder go please in the above code?
If you would like to set some placeholder when no option is selected in the dropdown then below
$form["field"][$key]["empty_option"] = true;
you can add the following line
$form["field"][$key]["empty_option_text"] = "Select location ...";