using the_content and the_tags witin map_poi_list.php

Home Forums MapPress Support using the_content and the_tags witin map_poi_list.php

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #14662
    danthonyl
    Participant

    I’m trying to use basic standard WordPress functions like the_content to display within my customized map_poi_list.php. How do I tell MapPress to pull the content for the specific POI displayed in the list.

    #14667
    danthonyl
    Participant

    Here’s a simplified version of my code in map_poi_list.php:

    <?php foreach($map->pois as $poi) : ?>
    <?php
       global $post;
       $postid = ($poi->postid) ? $poi->postid : $post->ID;
    ?>
    <div>
       <span><?php the_tags(); ?></span>
       <?php the_content(); ?>
    </div>
    <?php endforeach; ?>
    #14668
    Chris
    Keymaster

    Hi,

    Are you using a map or a mashup?

    WordPress has two types of functions: those that take a post ID and those that work on the global $post from The Loop. Usually the latter kind have ‘the_’ in the function name. A few functions can work either way (the post ID is optional).

    For mashups, the POI list is generated using AJAX. During AJAX calls there is no The Loop, so functions based on the global $post won’t work.

    For your situation it’s probably easiest to just use the functions that take a post ID:

    <?php
    	$postid = ($poi->postid) ? $poi->postid : $post->ID;
    	$post_ = get_post($postid);
    ?>
    <?php if ($post_) :?>
    <div>
       <span><?php echo get_the_tag_list('', ', ', '', $post_->ID); ?></span>
       <?php echo apply_filters('the_content', $post_->post_content); ?>
    </div>
    <?php endif; ?>
    

    If you must use the global $post functions, then you need to set up the global data before calling the function. For example:

    <?php
    	global $post;
    	if ($poi->postid && $post_ = get_post($poi->postid)) {
    		$post = $post_;
    		setup_postdata($post);
    	}
    ?>
    <?php if ($post_) : ?>
    <div><?php the_tags();?></div>
    <div><?php the_content();?></div>
    <?php endif; ?>
    
    #14670
    danthonyl
    Participant

    Thank you Chris for your quick reply. I implemented your first option in my mashup map and it worked perfectly. Thank you for saving me hours of headache!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.