Spatial queries

Once posts have geo_json, wp-geometa-lib lets a meta_query compare against a geometry with spatial SQL functions. The function name goes in compare and the other geometry, as GeoJSON, in value.

$point = '{"type":"Feature","geometry":{"type":"Point","coordinates":[144.9631,-37.8136]},"properties":{}}';

// Venues whose shape contains a point.
$q = new WP_Query( array(
    'post_type'  => 'gatherpress_venue',
    'meta_query' => array( array(
        'key'     => 'geo_json',
        'compare' => 'ST_Contains',
        'value'   => $point,
    ) ),
) );

// Posts ordered by distance from a point.
$q = new WP_Query( array(
    'post_type'  => 'post',
    'meta_query' => array( array(
        'key'     => 'geo_json',
        'compare' => 'ST_Distance_Sphere',
        'value'   => $point,
        'type'    => 'DECIMAL(10,2)',
    ) ),
    'orderby'    => 'meta_value_num',
    'order'      => 'ASC',
) );

Which functions are available depends on the database; they are the ones listed in the wp_geometa_capabilities option. The SRID defaults to 4326 and can be changed with the wpgm_geoquery_srid filter. Extra function names can be registered with wpgm_known_capabilities. See the upstream BrilliantPlugins/wp-geometa documentation for the full query syntax.