Solution: use a WP_Query to get objects for contextual maps
-
Hey Cyber Hobo, thanks for your great plugin, I love it.
This is not a really question, more a solution (don’t know a better place than the support forum to post it):
I want to use a WP_Query to get the objects for contextual maps (instead of using query_posts and affecting the main query).I use this simple solution, works great:
I changed line 1101 in geo-mashup.php
from:
$context_objects = $wp_query->posts;
to:
$context_objects = apply_filters(‘geo_mash_contextual_posts’, $wp_query->posts);The code in functions.php is then something like this:
function map_query_filter(){
$args = array(
//
);
$map_query = new WP_Query( $args );
return $map_query->posts;
}
add_filter(‘geo_mash_contextual_posts’,’map_query_filter’);Some real world example for people using post2post plugin:
On my site allcyclistsarebeautiful.com, when any Author page is being displayed, I want to show a map with all posts by the author and the all connected journeys.
In the post wrapper, after the content, I put a hook ‘para_postcontent_after’.
And in functions.php this (it’s little weird with my globals $post and $post_global, makes only sense in the context of my theme):function acab_content_add_map_author(){
$query_args = array(
‘author’ => $GLOBALS[‘author’],
‘nopaging’ => true,
);
$author_posts = new WP_Query( $query_args );$query_args = array(
‘connected_type’ => ‘user_to_journeys’,
‘connected_items’ => get_queried_object(),
‘nopaging’ => true,
);
$connected_journeys = new WP_Query( $query_args );$map_query = new WP_Query();
$map_query->posts = array_merge( $connected_journeys->posts, $author_posts->posts);
$map_query->post_count = $connected_journeys->post_count + $author_posts->post_count;return $map_query->posts;
}function acab_content_add_map(){
if ( get_the_id() != 278 ) return;
global $post;
$post_global_id = $GLOBALS[‘post_global’]->ID;$args_for_all = array(
‘height’ => ‘500’,
‘width’ => ‘100%’,
‘map_content’ => ‘global’,
‘zoom’ => ‘7’,
‘marker_select_attachments’ => ‘false’,
‘add_overview_control’ => ‘true’,
‘add_map_type_control’ => ‘false’,
‘load_empty_map’ => ‘true’,
‘click_to_load’ => ‘true’,
‘click_to_load_text’ => ‘click to load map’,
‘enable_scroll_wheel_zoom’ => ‘false’,
‘limit’ => ’50’
);if (is_author()){
add_filter(‘geo_mash_contextual_posts’, ‘acab_content_add_map_author’);
$args = $args_for_all;
$args[‘map_content’] = ‘contextual’;
echo GeoMashup::map( $args );}
}
add_action( ‘para_postcontent_after’, ‘acab_content_add_map’ );And this a question:
I don’t want to make changes in the plugin. Is it possible to get a filter in line 1101 in future releases?alright, be happy, happyHomelessHippie
- The topic ‘Solution: use a WP_Query to get objects for contextual maps’ is closed to new replies.