Support

Account

Forum Replies Created

  • Just thought I would add too this post.

    I had this same issue but did not want to deal with keeping the normalized postmeta fields _latitude and _longitude in sync with the ACF postmeta.

    This query “deserializes” the ACF google_maps field so no normalization is required. Obviously it would be better if ACF map field was just normalized by the plugin and not stored as serialized PHP object.

    
    function get_nearest_location_page($latitude, $longitude, $maxdistance = 100) {
    	global $wpdb;
    	$location_query = <<<EOF
    	SELECT wp_posts.post_title as post_title,
    	wp_posts.ID as post_id,
    	( 3959 * acos(
    	cos( radians( %f ) ) *
    	cos( radians( CONVERT(REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(location.meta_value,';',4),':',-1),'"',''),  DECIMAL( 10, 6 )) ) ) *
    	cos( radians( CONVERT(REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(location.meta_value,';',6),':',-1),'"',''),  DECIMAL( 10, 6 ))  ) - radians( %f ) ) +
    	sin( radians( %f ) ) * sin( radians( CONVERT(REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(location.meta_value,';',4),':',-1),'"',''),  DECIMAL( 10, 6 ))  ) )
    	) ) AS distance
    	FROM wp_postmeta as location, wp_posts
    	WHERE wp_posts.post_type = "page"
    	AND wp_posts.ID = location.post_id
    	AND location.meta_key LIKE "service_locations_%%"
    	HAVING distance < %f
    	ORDER BY distance ASC
    	LIMIT 1
    EOF;
    	$location_query_string = $wpdb->prepare($location_query, $latitude, $longitude, $latitude, $maxdistance);
    	return $wpdb->get_results($location_query_string, ARRAY_A);
    }
    

    in this case my field is actually an ACF Pro repeater field named service_locations.

  • Thanks, John! That wasn’t my issue, but I’ll move it just to be safe!

  • I figured it out…

    
    'new_post' => array(
    						'post_type'		=> 'dog',
    						'post_status'		=> 'published'
    					),

    …”published” isn’t a post_status option. “publish” is…

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