I have a function the_rooms defined as:

function the_rooms() {
    $latteParams['post'] = WpLatte::createPostEntity(
            'meta' => $GLOBALS['pageOptions'],
    $rooms = wp_get_post_terms($latteParams['post']->id, 'ait-dir-item-rooms');
        if ( !empty( $rooms ) && !is_wp_error( $rooms ) ){
            foreach ( $rooms as $room ) {
                echo $room->name;

This works in my single.php, but when I call it in another file, map-single-javascript.php:

data: '<div class="marker-holder"><div class="marker-content{ifset $item->thumbnailDir} with-image"><a href="{!$item->link}"><img src="{thumbnailResize $item->thumbnailDir, w => 120, h => 160}" alt="">{else}">{/ifset}<div class="map-item-info"><div class="title">$'+{ifset $item->optionsDir["price"]}{$item->optionsDir["price"]}+{/ifset}' <small><?php the_rooms(); ?>bd/<?php the_baths(); ?>ba</small></div><div class="address">'+{ifset $item->optionsDir["address"]}{$item->optionsDir["address"]|nl2br}+{/ifset}'<br>'+{ifset $item->optionsDir["address2"]}{$item->optionsDir["address2"]|nl2br}+{/ifset}'</div><div class="timestamp"><?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></div></div></a><div class="arrow"></div><div class="close">x</div></div></div></div>'

It returns nothing.

Is this because it isn’t being called inside the loop? How can I get it to work in map-single-javascript.php?

Thank you!

Read more here: PHP in AJAX with WordPress


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, ,

Wordpress related questions and answers: