• Resolved Tonton Carton

    (@tonton-carton)


    Hi everybody
    Awesome plugin many thanks to author!

    Athough not sure this is relevant or might be of any interest for someone, here is how I display all posts from a user on a map on their profile (as you will see, i’m a beginner):

    <?php global $current_user;
    get_currentuserinfo();                      
    
    $args = array(
    	'author'        =>  $current_user->ID,
    	'showposts'        =>  '-1',
    	'post_status' => 'publish'
        );
    
    $the_query = new WP_Query( $args );
    if ( $the_query->have_posts() ) {
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
     ?>
    		<div style="display:none;"><?php echo '' . get_the_ID() . ','; ?></div>
    
    <?php }
    echo GeoMashup::map(
    		array(
    			'map_content' => $the_query
    		)
    	);
        }  ?>
    <?php wp_reset_postdata(); ?>

    Works well.
    (Is it ugly ?)

    ***

    Anyway, being unfamiliar with wp i’m having trouble when i want to display current user’s favorite posts on a map (using Wp Favorite Posts plugin), ie the posts that an user saved as his/her favorites.

    I managed to get the good list of IDs separated by comas, just like above code. But it is with a “foreach” thing and i don’t know how to use it in my geomashup parameters.

    Tried everything (queries, printf, …), nothing worked. This is the basis :

    <?php
            $options = wpfp_get_options();
            $favorite_post_ids = wpfp_get_users_favorites();
    
        foreach ($favorite_post_ids as $post_id) {
            $p = get_post($post_id);
    
            echo " " . $p->ID . ", ";
        }
    //ok it actually displays a list of current user's favorite post separated by commas but how do i insert result inside this:
    echo GeoMashup::map(
    		array(
    			'map_content' => //here the result?!
    		)
    	);
     ?>

    Is this possible to “transform” this foreach thing into a regular query, just like in my first code? Or just use the output directly..?
    Maybe this is very simple for someone… i feel rubish.

    Will update if solution is found. Sorry if not useful nor the right place to post. and definately for beeing so long.

    Any help appreciated!
    Cheers

    https://www.ads-software.com/plugins/geo-mashup/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Tonton Carton

    (@tonton-carton)

    Hi, still trying to show user’s favorite posts on map and if anyone interested this is the update

    Please not that the ‘echoed’ datas are just here to see if the good IDs are retrieved until mapping works nicely..

    <?php
    $favorite_post_ids = wpfp_get_users_favorites();
    $string=implode(",",$favorite_post_ids);
    echo $string;
    $args = array(
    	'showposts'        =>  '-1',
    	'post_status' => 'publish',
    	'post__in'        =>  array($string)
        );
    $the_query = new WP_Query( $args );
    if ( $the_query->have_posts() ) {
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
     ?>
    		<?php echo '' . get_the_ID() . ','; ?>
    
    <?php }
    
        }  
    
    echo GeoMashup::map(
    		array(
    			'map_content' => $the_query
    		)
    	);
    ?>

    Getting close to it but still not good.

    The echo $string; gets me the good ids: “501,1043”

    But the echo '' . get_the_ID() . ','; of the_query retrieves wrong ids: “812, 286, 20,” and these 3 wrong posts appear on the map.

    Also tried “object_name” combined with “object_ids” method in geomashup parameters but not good.

    edit: semms the issue is about sticky posts. the_query retrieves only stickies.
    I tried among other things
    ‘post__not_in’ => get_option( ‘sticky_posts’ ),
    or
    ‘ignore_sticky_posts’ => 1,
    but no good result yet.

    Thread Starter Tonton Carton

    (@tonton-carton)

    Hi again.. think i finally found the solution for user’s favorite posts on a map:

    <?php
    $favorite_post_ids = wpfp_get_users_favorites();
    $string=implode(",",$favorite_post_ids);
    echo GeoMashup::map(
    		array(
    			'map_content' => 'global',
    			'showposts'        =>  -1,
    			'object_name' => 'post',
    			'object_ids' => $string
    		)
    	);
    ?>

    Now i’ve got user’s posts on a map and user’s favorite posts on an other map. Perfect.
    Again, sorry for all these long messages! maybe this can be helpful to someone else.

    Cheers

    Plugin Author Dylan Kuhn

    (@cyberhobo)

    Looks good, thanks for sharing your work!

    Looks great! Where have I to put the code in?

    Thread Starter Tonton Carton

    (@tonton-carton)

    ‘Welcome!
    Tiger i guess you may put it anywhere you want your map to appear, just like <?php echo GeoMashup::map() ?> template tag.
    I actually put it in a profile page content.

    Note: wpfp_get_users_favorites(); accepts user name, something like:

    wpfp_get_users_favorites(Tonton);

    ++

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display user posts on map (solution 1 more request for user's favorites)’ is closed to new replies.