Digital Sovereignty for everyone

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.

If you like this plugin please consider making a donation to further development

Install LHero.org

lhero.org

Open it straight from your home screen, full screen and quicker to load.

  1. Tap the Share button . If you cannot see it, tap ••• first.
  2. Scroll down and tap Add to Home Screen.
  3. Tap Add.
  1. Tap the browser menu â‹®.
  2. Tap Install app or Add to Home screen.
  1. In the menu bar, choose File, then Add to Dock.

Use your browser's menu to install this site or add it to your home screen.