• Resolved befeleme

    (@befeleme)


    Hello,
    please, I need in adding form cca only 10 locations in field type: select and user select only one of this. Now user can only manually add location as text.

    Its simply way for this?

    Thanks.

    • This topic was modified 2 years, 2 months ago by befeleme.
    • This topic was modified 2 years, 2 months ago by befeleme.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    you can do that either with the Maps and Locations extension or by adding the code below in your theme functions.php file (or even better create a new blank plugin https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/ and paste the code there so it will not be overwritten on the theme update).

    
    add_filter( "adverts_form_load", function( $form ) {
    	if( $form["name"] != "advert" ) {
    		return $form;	
    	}
    	$options = array(
    		array( "value" => "London", "text" => "London" ),
    		array( "value" => "New York", "text" => "New York" ),
    	);
    	foreach( $form["field"] as $k => $f ) {
    		if( $f["name"] == "adverts_location" ) {
    			$form["field"][$k]["type"] = "adverts_field_select";
    			$form["field"][$k]["empty_option"] = true;
    			$form["field"][$k]["empty_option_text"] = "Select location ...";
    			$form["field"][$k]["options"] = $options;
    		}
    	}
    	return $form;
    } );
    

    The locations you would like to show you need to customize in the above snippet.

    Thread Starter befeleme

    (@befeleme)

    Hi Greg,
    thank you very much. B.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Text location replace by selecting locations’ is closed to new replies.