WordPress.org

Ready to get started?Download WordPress

Forums

Geo Mashup
[resolved] Add/remove pins based upon drop down options (30 posts)

  1. mariostella
    Member
    Posted 3 years ago #

    Hi,
    What I am trying to accomplish is getting an interactive map that shows pins based on custom fields associated with it.
    So, if I have pins for New York, Albany and Boston about ball parks, football fields and baseball fields, I am trying to pair the mashed up map with check boxes to show any of both or only one and any combination in between.

    So far I tinkered with categories and with this http://wiki.geo-mashup.org/guides/custom-marker-depending-on-a-custom-field-value but I have no idea on how to tie the two in so I can accomplish the same category check boxes effect with custom fields. Sure I could use categories. On a fresh installation I would, but this is far rom fresh and I use categories in a non canonical way.

    Can you help? Pointers? Thanks

    http://wordpress.org/extend/plugins/geo-mashup/

  2. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    This will take some development for sure, but the guide you're tinkering with is the right idea. You'd add your custom field data as it's done there, then build your own interface using that data in the custom javascript part. That way you can just ignore categories altogether.

    The javascript API is unfortunately still pretty obscure and subject to change. The resources available now are in an issue on the topic and the geo-mashup.js code itself. If you're game to help me improve this situation, chime in on that issue and I'll give you some more ideas. I use the API a lot and it is improving, but I need help with testing, use cases, documentation, and such.

    cheers,
    -dylan-

  3. mariostella
    Member
    Posted 3 years ago #

    Thanks for your reply. I'd love to help, but I am just a tinkerer, no coding skills...if I manage to pull out something decent I will let you know. Thanks for your plugin!

  4. mariostella
    Member
    Posted 3 years ago #

    Hi!
    I found your suggestion on issue 250

    <?php
    $categories = get_the_category();
    $cat_ids = array();
    foreach( $categories as $category ) {
      $cat_ids[] = $category->cat_ID;
    }
    $map_args = 'map_content=global&open_post_id=' . get_the_ID() .
      '&marker_select_center=true&marker_select_highlight=true' .
      '&marker_select_highlight=true&marker_select_attachments=true' .
      '&map_cat=' . implode(',', $cat_ids);
    echo GeoMashup::map( $map_args );
    ?>

    Do you think it could work with custom fields?

    <?php
    $customfield = get_post_meta($post_id, 'my_key', 'false');
    
    $map_args = 'map_content=global&open_post_id=' . get_the_ID() .
      '&marker_select_center=true&marker_select_highlight=true' .
      '&marker_select_highlight=true&marker_select_attachments=true';
    echo GeoMashup::map( $map_args );
    ?>

    If this worked I could use a post method to pass the variables I need and after submitting geo mashup would show the map with the parameters selected.
    What do you think? Thanks!

  5. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    That example makes a map of posts in the same categories as the current post. So do you want to make a map of posts with the same custom fields as the current post? That doesn't sound like what you want.

  6. mariostella
    Member
    Posted 3 years ago #

    Mmmhh nope, you are right, I wanted to know if using a function of the likes (similar to the one I wrote) I can pull out all the post IDs with a specific meta key and value (or two, or three...) and feed them to geo-mashup to create a global map.

  7. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

  8. mariostella
    Member
    Posted 3 years ago #

    Hello!
    Thanks a lot! I did not know contextual maps supported queries! I plan on having more than 100 posts, so I hope the error mentioned in the page you sent me gets resolved in the future!
    I will let you know if it works. Thanks again!

  9. mariostella
    Member
    Posted 3 years ago #

    Hi,
    Unfortunately only a few queries work correctly.

    I am using the code in the loop and calling a specific key as such

    <?php query_posts( 'meta_key=type' ); ?>
    <?php echo GeoMashup::map( 'map_content=contextual' ); ?>
    <?php wp_reset_query(); ?>

    What happens is the map centers as if it had no values (to 0,0 coord and zooms all the way in)

    The same happens if I use both key and value or only a value. With one tag it works fine, but I have not tested multiple tags. I am not really interested in tags personally.

    I did test categories, which partially work since I can only get to show 10 markers on the map no matter how many categories I call.

    <?php query_posts( 'cat=16,4,29,7,8,9,13,12,20,19,11,15,17,26,27,28,10,21,5,6,3,18,14' ); ?>
    <?php echo GeoMashup::map( 'map_content=contextual' ); ?>
    <?php wp_reset_query(); ?>

    So yes this would solve the initial question if it worked properly with queries. Any idea what it could be? Thanks

  10. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    You may want to try a listing your query results to make sure they are right:

    <?php query_posts( 'meta_key=type' ); ?>
    Results:<ol>
    <?php while( have_posts() ) : the_post(); ?>
    <li><?php the_title(); ?></li>
    <?php endwhile; ?>
    </ol>
    <?php wp_reset_query(); ?>

    With the categories, you probably need to set posts_per_page to -1 to get more than 10.

  11. mariostella
    Member
    Posted 3 years ago #

    Right on both. Get all posts with -1 for cat and get no posts with the query list (I tried it in and outside the loop)
    This leaves me thinking I might have a problem with my WP installation? I do not understand why those queries are not executed.
    BTW, I inserted the custom fields with the more fields plugin. Could that make a difference?

  12. mariostella
    Member
    Posted 3 years ago #

    Hi,
    I am using this query, which works well to output a list of posts anywhere lse on my site. But when I insert the geo-mashup code it outputs a number of blank maps equal to the number of posts that fulfill the query parameters.

    <?php
    
     $querystr = "
    SELECT $wpdb->posts.* FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    WHERE $wpdb->posts.post_status = 'publish'
    AND $wpdb->posts.post_type = 'post'
    AND $wpdb->postmeta.meta_value = 'LI'
    ORDER BY $wpdb->posts.post_modified DESC
    ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    ?>
     <?php if ($pageposts): ?>
      <?php foreach ($pageposts as $post): ?>
       <?php setup_postdata($post); ?>
    
    <?php echo GeoMashup::map( 'map_content=contextual&height=400&width=700&remove_geo_mashup_logo=true&cluster_max_zoom=11&zoom=8' ); ?>
    <?php echo GeoMashup::category_legend() ?>
    
      <?php endforeach; ?>
     <?php endif; ?>

    Guess geo mashup does not work with this kind of queries? What function should I call to use geo mashup filters? (hope what I am saying makes sense)

  13. mariostella
    Member
    Posted 3 years ago #

    Also I have to correct one earlier statement. Adding the posts_per_page=-1 parameter to the query increases the number of posts but still does not outputs them all. Right now it is short of 6. I checked one of the missing ones and there seems to be no issue with it, as even the single map displays correctly. The data is stored and everything should work, but the post does not appear.
    The global map shows everything fine.

  14. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    Are you saying the posts appear when you loop through them, but don't appear on a contextual map? It might be a good check to include coordinates in the list:

    <?php query_posts( 'meta_key=type' ); ?>
    Results:<ol>
    <?php while( have_posts() ) : the_post(); ?>
    <li><?php the_title(); ?>
    <?php echo GeoMashup::location_info('fields=lat,lng'); ?></li>
    <?php endwhile; ?>
    </ol>
    <?php wp_reset_query(); ?>
  15. mariostella
    Member
    Posted 3 years ago #

    Hi thanks Dylan,
    Not working. It only outputs "Results:" with nothing at all below

    Also, about not all the properties showing up. It has to do with clustering. After removing clustering and cleaning the cache of the browser several times I got all the posts to show up. But I am not sure what returning users will see if they do not clean the cache of their browsers. Plus when I resume clustering the issue returns showing all posts but one on a certain zoom level and it is short of three if I zoom one level out, short of two at another zoom level, and so on. Is there any issue like this open?

  16. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    No, this is the first I've heard of incorrect clustering. I don't know what's going on - I can't seem to reproduce any of this behavior. There's not much I can do without being able to see the behavior except make guesses.

  17. mariostella
    Member
    Posted 3 years ago #

    Hi,
    Can I send you my test page in private?

  18. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    Sure, my email address is cyberhobo at cyberhobo dot net.

  19. mariostella
    Member
    Posted 3 years ago #

    Hi, thanks, just sent it.

    Also, would you have a clue of why nothing is returned with the query? Even adding coordinates?

    Are you saying the posts appear when you loop through them, but don't appear on a contextual map?

    Yes. The same query outputs, say, a list of posts titles, or whatever is set to appear, with the query I gave you. If I insert the geo mashup code it returns a series of empty maps, one per each post that was supposed to be on the map.

  20. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    Ok, the first question: why does the first query return nothing? The meta_key must be wrong. In your SQL example you're querying by meta_value, so maybe the equivalent call to query_posts() should be something like query_posts( 'meta_value=LI' ).

    The second question was, why are the maps in the loop empty? I think it's because you're using contextual map content, which looks at the WordPress query for content, but you've done your own query in this case, so there is nothing to be found in the WordPress global query.

  21. mariostella
    Member
    Posted 3 years ago #

    Hi,
    As for the first question: I just tried again with the following query inserted within the loop and outside the loop (tried both ways)

    <?php query_posts( 'meta_value=LI' ); ?>
    Results:<ol>
    <?php while( have_posts() ) : the_post(); ?>
    <li><?php the_title(); ?>
    <?php echo GeoMashup::location_info('fields=lat,lng'); ?></li>
    <?php endwhile; ?>
    </ol>
    <?php wp_reset_query(); ?>

    The output was nothing as before. I do not get why, as I do query for that meta value in other parts of the site and do get results, even as of now. I use the custom query you saw above, though.

    As for the second question: That makes sense. So what type of query can I use with contextual maps? Sorry if these questions may seem redundant and banal, I am quite a rookie at all this.
    Thanks

  22. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    I'd have to look at the SQL WordPress is generating to see what the difference is - to my mind that query_posts() call should be equivalent to your custom query. I don't see this as a Geo Mashup issue - you're working on getting your WordPress query right. It may require quite a bit of learning about WordPress.

  23. mariostella
    Member
    Posted 3 years ago #

    Thanks. I am in for learning. If I sent you the SQL output (where do I get it??) would you point me towards some direction so I could find a way myself?

  24. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    After a call to query_posts(), look at the output of var_dump( $wp_query->last_request ); for the SQL.

  25. mariostella
    Member
    Posted 3 years ago #

    Thanks. Ok this is weird. I tested it on another WP installation and the query returns results. The usual WP installation still does not return results.

    I inserted the query:

    <?php query_posts( 'meta_value=LI' );
    var_dump( $wp_query->last_request );?>
    Results:<ol>
    <?php while( have_posts() ) : the_post(); ?>
    <li><?php the_title(); ?>
    <?php echo GeoMashup::location_info('fields=lat,lng'); ?></li>
    <?php endwhile; ?>
    </ol>
    <?php wp_reset_query(); ?>

    And with the other installation I got

    NULL Results:

    1. Post Title43.2549171,12.1698694
    So it works right?

    The usual installation (the one not working) just outputs

    NULL Results:

    Got no idea why it is NULL in both cases, but in one case it works. May it be a plugin creating the issue?? One is wp 2.9 (the one not working) the other one is 3.0.4 and both have the same exact plugins installed.

  26. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    I made a mistake, the debug code should be var_dump( $wp_query->request );. Hopefully that will show you the SQL, and the difference will be visible.

  27. mariostella
    Member
    Posted 3 years ago #

    Yes that output the SQL, and I can spot some random query that is really uncalled for!!

    This is the working one

    string(302) " SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')AND wp_postmeta.meta_value = 'LI' ORDER BY post_date DESC LIMIT 0, 10"

    And this is the not working one

    string(380) " SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish')AND wp_postmeta.meta_value = 'LI' AND wp_postmeta.meta_key = 'budget' ORDER BY (wp_postmeta.meta_value+0) DESC LIMIT 0, 10"

    You can tell there are some weird calls to meta key "budget", which is one of the keys, but certainly not called in the query. I have no idea why this is the case. Could any other custom query in the template be injecting those in the custom query? Thanks for the SQL query by the way! It is a great tool for debugging!

  28. Dylan Kuhn
    Member
    Plugin Author

    Posted 3 years ago #

    I'd suspect that code in a plugin or possibly the theme is injecting the unwanted code. Sometimes the suppress_filters parameter will prevent it:

    query_posts( 'meta_value=LI&suppress_filters=1' );

    In any case, I think we've eliminated Geo Mashup as the cause, no?

  29. mariostella
    Member
    Posted 3 years ago #

    Yes, that is right, Geo Mashup is not the cause, that was clear from the moment I had one installation working and the other not working. I was just asking a little extra help from you to head towards the right direction, and you did help. Thanks a lot!

    PS: suppress_filters did the trick!! Thanks a lot again!

  30. mariostella
    Member
    Posted 3 years ago #

    Also for others that maybe encounter similar issues:
    I found out that using arrays also works great and I can select only posts that belong to a certain number of categories and return only those that satisfy all the categories queried. I do not need to suppress filters with the array.

    An example is:

    query_posts(array('category__and'=>array(2,6),'showposts'=>2,'orderby'=>title,'order'=>DESC));

    It will take any parameter as if it was outside the array using the above syntax.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags