Skip to content

Instantly share code, notes, and snippets.

@jerclarke
Created April 30, 2015 20:00
Show Gist options
  • Save jerclarke/380897120a928862d93e to your computer and use it in GitHub Desktop.
Save jerclarke/380897120a928862d93e to your computer and use it in GitHub Desktop.
Filter Geo Mashup to include 'inherit' status when querying for 'attachment' posts
<?php
/**
* Filter geo mashup 'where' clause to insert 'inherit' as a valid status when attachments are being queried
*
* By default geo mashup locations queries (i.e. posts queried inside the map) include the 'attachment' post type
* along with posts when post_type=all BUT it only checks for post_status=publish, so attachments are never part
* of the returned results.
*
* This function filters the 'where' clause of the locations query to add 'inherit' as a valid post status when
* attachments are a valid post type. It won't do anything if attachments aren't already part of the query and
* posts are never 'inherit' status anyway so it should be safe.
*
* NOTE: As of Geo Mashup 1.8.3 this hack isn't enough! We also need to edit GeoMashupQuery::generate_object_html()
* to insert 'inherit' as a valid status. The plugin seems to have a list of all possible statuses at that point because it
* already knows which posts it wants to show, so we just need to add inherit to the list.)
*/
function sarah_filter_geo_mashup_locations_where($where) {
// Only filter if it's exactly what we expect Fetching attachments that are published (STUPID)
if (!strpos($where, "post_status = 'publish'") OR !strpos($where, "o.post_type IN ('post', 'page', 'attachment')"))
return $where;
// Add inherit
$where = str_replace("post_status = 'publish'", "post_status in( 'publish', 'inherit')", $where);
return $where;
}
add_filter( 'geo_mashup_locations_where', 'sarah_filter_geo_mashup_locations_where');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment