1. Go to this page and download the library: Download wp-forge/wp-geo-query library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wp-forge / wp-geo-query example snippets
$query = new WP_Query(
array(
'geo_query' => array(
'lat' => 0,
'lng' => 0,
'distance' => 25, // Default value is 25
'units' => 'miles', // Default is miles, could also be 'mi', 'km', or 'kilometers'
'lat_key' => 'geo_latitude', // Default value is 'geo_latitude'
'lng_key' => 'geo_longitude', // Default value is 'geo_longitude'
),
// ...
)
);
add_action(
'pre_get_posts',
function ( WP_Query $query ) {
if ( $query->is_main_query() /* Customize your conditional to meet your needs */ ) {
$query->set(
'geo_query',
array(
'lat' => 0,
'lng' => 0,
'distance' => 25, // Default value is 25
'units' => 'miles', // Default value is 'miles', could also be 'mi', 'km', or 'kilometers'
'lat_key' => 'geo_latitude', // Default value is 'geo_latitude'
'lng_key' => 'geo_longitude', // Default value is 'geo_longitude'
)
);
}
}
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.