Home › Forums › MapPress Support › MapPress Show Date and Category on Mashup Pop Ups › Reply To: MapPress Show Date and Category on Mashup Pop Ups
Hi,
The WP functions that begin with ‘the_’ (like the_time) are really meant to work only on a global current post, in the theme’s “The Loop” section.
The mashup has its own query so the ‘the_’ functions won’t work. But there are two workarounds:
1) Find the corresponding WP function that uses a post or post ID instead. For example, instead of the_time(‘F’), call get_the_time(‘F’, $post_id) instead. Not all template functions have a clear analog, for example get_the_category() has to be replaced with get_the_terms().
2) Save the current post from The Loop, set up the mashup post, and then restore the current post. Then you can use ‘the_’ functions in the mashup.
Example code for #1:
<?php
$post = $poi->get_post();
if ($post) {
echo get_the_time( 'F j, Y', $post) . "<br/>";
$terms = get_the_terms( $post->ID, 'category');
if (isset($terms[0]))
echo $terms[0]->name;
}
?>
Example for #2:
<?php
global $post;
// Save current post from The Loop
$current_post = ($post) ? clone($post) : null;
$post = $poi->get_post();
if ($post) {
setup_postdata($post);
echo the_time( 'F j, Y') . "<br/>";
$categories = get_the_category();
if (isset($categories[0]))
echo $categories[0]->cat_name;
// Restore original post so we don't interfere with The Loop
if ($current_post) {
$post = $current_post;
setup_postdata($current_post);
}
}
?>