Home Forums General Issues ACF with wp-advanced-search


ACF with wp-advanced-search

  • I’m having issues using ACF in conjunction with another plugin,

    I have some code for the form that takes the structure of:

    $args['fields'][] = array('type' => 'meta_key',
    		'label' => 'Location',
    		'meta_key' => 'address_city', 
    		'format' => 'select',
                     'values' => array('' => 'Any', 'city1' => 'City1', 'city2' => 'City2', etc... ), 
    		 'operator' => 'IN');

    For the purpose of the exercise, I need to auto-populate this selector with content from the custom fields. In this case, the custom field is called ‘Address City’. I’ve attempted to do this by creating a function called Cities(). This has been verified by the plugin creator as a viable method.

    $args['fields'][] = array('type' => 'meta_key',
    		'label' => 'Location',
    		'meta_key' => 'address_city', 
    		'format' => 'select',
                     'values' => Cities(), 
    		 'operator' => 'IN');

    My Cities() function looks as follows:

    function Cities() {
    	$args = array(
                    'post_type' => 'property',
                    'posts_per_page' => '-1'
       	$inner_query = new WP_Query( $args );
        $temp = array(); 
    	$cities = array();
    	$counter = 0;
    	while ( $inner_query->have_posts() ) : $inner_query->the_post();
    			$field_key = "field_53ea04d8b96b6";
    			$post_id = get_the_ID() ;
    			$field = get_field_object($field_key, $post_id);
    			$cities[$counter] =  $field['value'];
    	$counter++; endwhile;
    	$result = array_unique($cities);	
    	foreach($result as $key => $value) {
    		$key = $value;
    		$a[$key] = $value;
    	return $a;

    I appreciate my code is messy, but I can’t get this to work properly, as the array is not being returned in the correct format. Does anyone have any ideas as to how I can return the array of all fields in the form of:

    [value] => [label]


Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.