Giter Site home page Giter Site logo

fyaconiello / wp-geo-posts-deprecated- Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 11.0 49 KB

A simple wordpress plugin for adding geodata to posts - this is pretty much abandoned. use at your own risk.

Home Page: http://wordpress.org/extend/plugins/wp-geoposts/

PHP 100.00%

wp-geo-posts-deprecated-'s Introduction

[DEPRECATED] - Please do not use this repo as-is

Notes:

  • Google puts rate limiting on the host IP, this solution may not work well on shared hosts
  • The google geocoding api has changed

wp-geo-posts

A simple Wordpress plugin for adding geographic data to posts.

Features

  1. Adds location, latitude, and longitude meta + metaboxes to any content type.
  2. Provides an easy to use interface for selecting which content types to apply the above meta values. Note: this allows selection of built in types: page and post as well as any registered custom post types.
  3. Provides WP_GeoQuery an extended WP_Query class for doing distance based and geo-aware queries.
  4. Has support for within radius option to WP_GeoQuery
Coming Soon!
  • Get Directions link (utilizing Google Maps)
  • Custom Markers by post type.
  • Shortags for:
  • Static Map - show one or more posts on a static map
  • Dynamic Map
  • Option to show radius as overlay
  • Show one or more posts

Installation

  1. Upload the entire wp-geo-posts folder to the /wp-content/plugins/ directory.
  2. Activate the plugin through the Plugins menu in WordPress.

Setup

  1. Click the Settings link on the plugin management page OR click the WP GeoPosts link from the Settings flyout menu.
  2. Generate a Google Maps API Key and enter it into the provided text input. Note: this is optional and used for Google Maps API calls.
  3. Select all of the content types that you wish to attach georelated content from the leftmost bank of choices and move them to the rightmost column.
  4. Submit the Form by clicking Save Changes.

Usage

Metaboxes

For every post type selected on the plugin settings page. That type's add/edit screens will have an additional metabox automatically added. Metadata that is added to each record:

  • Location via wp_gp_location
  • Latitude via wp_gp_latitude
  • Longitude via wp_gp_longitude

Latitude and Longitude are readonly attributes of the metabox. Their values are automatically generated on save via a call to Google's geoencoding api.

WP_GeoQuery Usage

Make a geo-aware query against the posts table. WP_GeoQuery accepts all arguments that WP_Query takes. latitude and longitude are optional parameters. If passed, distance is calculated and returned with each result. In addition to the regular fields, each result returns latitude, longitude, and location.

<?php
$query = new WP_GeoQuery(array(
  'latitude' => '37.5160', // User's Latitude (optional)
  'longitude' => '-77.5005', // User's Longitude (optional)
  'radius' => 25, // Radius to select for in miles (optional)
  'posts_per_page' => 25, // Any regular options available via WP_Query
));
foreach($query->posts as $post)
{
	echo " {$post->post_title}<br />\n";

	// returned only if latitude and longitude are passed into WP_GeoQuery
	echo " {$post->distance}<br />\n";

	// Always returned by WP_GeoQuery
	echo " {$post->location}<br />\n";
	echo " {$post->latitude}<br />\n";
	echo " {$post->longitude}<br />\n";
	echo "<br />\n";
}
?>

wp-geo-posts-deprecated-'s People

Contributors

fyaconiello avatar roborourke avatar

Stargazers

 avatar Phil Barbato avatar Christophe Vergne avatar  avatar Daniele Scotti avatar John Wilson avatar Chris Van Patten avatar  avatar Thomas avatar Angus H. avatar  avatar Ryan Nutt avatar Abdulatif Henno avatar Archonic avatar Paul de Wouters  avatar James Douglas avatar Richard avatar Luke Seager avatar Mirco Babini avatar  avatar Jon Campbell avatar Jean-Charles Bournot avatar  avatar Oli Young avatar Timothy Wood avatar  avatar

Watchers

Luke Seager avatar Ryan Brinks avatar

wp-geo-posts-deprecated-'s Issues

'cat'=>$category_id,

$category_id = $_GET["cat"];

$args=array(
's'=>$get_s,
'cat'=>$category_id,
'latitude' => $get_latitude, // User's Latitude (optional)
'longitude' => $get_longitude, // User's Longitude (optional)
'radius' => $get_radius, // Radius to select for in miles (optional)
'posts_per_page' => $get_postsperpage,
'paged' => get_query_var('paged'),
);

Search width cat='1' is not working.

Posts with exact same address

Haven't tested this too thoroughly, but it looks like posts with the exact same address may bug out when plotted and grouped on map.

Wp_Geoquery

ok so the geo never closes. you cant reset it so to speak. and since there can only be one instance of the query going at a time it breaks any querys post that query.

        parent::__construct($args);

        remove_filter( 'posts_fields', array( $this, 'posts_fields' ) );
        remove_filter( 'posts_join', array( $this, 'posts_join' ) );
        remove_filter( 'posts_where', array( $this, 'posts_where' ) );
        remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) );

This needs to be added to geo_query.php of your plugin at line 57

this is pretty crucial

meta_query

Adding meta_query to the WP_GeoQuery class seems to break the query and no results are returned (if the lat and long values are entered):

$wp_query = new WP_GeoQuery(array(
'post_type' => array( 'locations' ),
'order' => 'DESC',
'orderby' => 'date',
'posts_per_page' => '12',
'paged' => $paged,
'meta_query' => array(
array(
'key' => 'key_here',
'value' => 'yes',
'compare' => 'IN',
)
),
'latitude' => $lat, // User's Latitude (optional)
'longitude' => $lng, // User's Longitude (optional)
'radius' => 20, // Radius to select for in miles (optional)
));

Geo locate Issue

When using a cloud site server it errors out because the servers ip has been blocked for MAX_QUERY_LIMIT being reach. the work around for this is changing a chunk of code in geo-post.php.

$location = $_POST['wp_gp_location'];
// Save the Location
update_post_meta($post_id, 'wp_gp_location', $location);

$location_san_spaces = str_replace(' ', '%20', $location);  
// Made this variable to swap spaces for %20's because urlencode() adds +'s which nominatim doesnt support

// Try to geolocate
$obj = json_decode(file_get_contents('http://nominatim.openstreetmap.org/search/' . $location_san_spaces . '?format=json'));
//Changed the obj from google to nominatim

// If successful
if($obj != '')
{
try
{
    if(empty($latitude))
    {
        $latitude   = $obj[0]->lat;
        update_post_meta($post_id, 'wp_gp_latitude', (string)$latitude);
                    //Change the obj -> lat
    }

    if(empty($longitude))
    {
        $longitude  = $obj[0]->lon;
        update_post_meta($post_id, 'wp_gp_longitude', (string)$longitude);
                    //Change the obj -> lon
    }
}
}

tax_query and radius bug

Hi,

Great plugin! I've just noticed a bug though.

If I use this query:

$query = new  WP_GeoQuery(array(
    'post_type' => 'event',
    'tax_query' => array(
        array(
            'taxonomy' => 'main-cat',
            'field' => 'slug',
            'terms' => 'special-events'
        )
    ),
    'posts_per_page' => 10,
    'paged' => get_query_var( 'page' ) ? get_query_var( 'page' ) : 1,


    // location stuff
    'latitude' => $lat
    'longitude' => $long
    'radius' => 25
));

It returns no posts, however removing 'radius' pulls the correct posts. Also removing 'tax_query' pulls the correct posts.

So using radius and any kind of taxonomy query by the looks of it breaks. I have also tried just 'main-cat' => 'special-events' and this breaks if Radius is used also.

Geolocation not happening

On save in WP admin, lat and long will occasionally not be generated. When troubleshooting, I tried echoing/dumping the json which was empty.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.