Support

Account

Home Forums General Issues Query posts by custom field 'Google Map'

Solved

Query posts by custom field 'Google Map'

  • hello all,

    My custom post types have Google Map field. I’d like to query them by that field.

    There is a guide Query posts by custom fields which I am trying to follow for my needs.

    My query should return all places within map bounds. It should look like this:

    
    $args = array(
    	'post_type'	=> 'place',
    	'meta_query'	=> array(
    		'relation'		=> 'AND',
    		array(
    			'key'		=> 'Google Map field',
    			'value'		=> 'Latitude',
    			'compare'	=> 'between $north and $south'
    		),
    		array(
    			'key'		=> 'Google Map field',
    			'value'		=> 'Longitude',
    			'compare'	=> 'between $east and $west'
    		)
    	)
    );
    

    Is it possible access ‘Google Map field’->Latitude and ‘Google Map field’->Longitude within the query?

  • The ACF google map field stores a serialized array of values. It is impossible to search these values in the manner you describe.

    In order to do a search on longitude and latitude you would need to create an acf/save_post filter. In this filter you get the value of the ACF google map field without formatting.

    
    $value = get_field('map-field-name', $post_id, false)
    

    You would then save these values into WP custom meta using update_post_mata(). You can then uses these fields for your search.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.