June 6, 2012 at 8:59 am #9564Ryan SandersParticipant
I’ve created a custom post type and associated MapPress with it. On the individual pages, the Map displays great. Now I’m creating custom overall page templates to display all posts in that custom post type and using a loop such as:
<?php $loop = new WP_Query( 'post_type=places-to-stay' ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_title( '<h2><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>
<?php the_content(); ?> </div>
<?php endwhile; ?>
However, when I use [mashup display="current"] in the template (well, you know, doshortcode etc etc) I get a world map with no locations on it even though I'm displaying all of the custom posts on the page, all of which have maps associated with them.
I guess my big question is: How is [mashup] finding the posts with maps that are current displayed? If I print_r each post as post, I don't see any data referring to the map.
Hope this makes sense,
-RyanJune 6, 2012 at 12:22 pm #9565ChrisKeymaster
I’m assuming your actual parameters are [mashup show=”current”] (‘display’ isn’t a valid argument).
To answer your question: the mashup uses the WP query global $wp_query. WordPress sets $wp_query to the current query for the page, based on the post/get parameters for the page. For show=’current’, MapPress reads the $wp_query object and loops through the posts. For each post it fetches the maps for that post using MapPress function get_post_map_list(). It then loops through the pois for each map and adds them to the mashup.
I think the problem is that the $wp_query global isn’t being set on your template. Using new WP_Query() won’t set it. So, MapPress is probably reading whatever was originally set for the page – which is probably empty.
If you use query_posts() instead of new WP_Query, WordPress will create the WP_Query object and then also overwrite the $wp_query global as well. The Codex has some explanation:
Some solutions might be:
1) Use query_posts() instead of creating a WP_Query object. I think this is the easiest, if it’ll work for you.
2) Explicitly use the same query in the mashup as you’re using in the template. It might be tricky if you’re paging results, but if you’re just displaying all the posts in a category it wouldn’t matter.
I hope that helps!
- You must be logged in to reply to this topic.