Hi folks,
I'm looking to return results from PW in an Ajax call, but I'm not sure if I'm going about this the right (or preferred) way.
I created a script in /htdocs/public/ajax/affiliates.php, which is called using Ajax.
The script itself bootstraps Processwire and returns JSON for all affiliates. It looks something like this:
<?php
require_once '../../index.php';
$data['markers'] = array();
$markers = array();
$affiliates = wire()->pages->find("template=affiliate");
foreach ($affiliates AS $affiliate)
{
$marker['latitude'] = $affiliate->mapmarker->lat;
$marker['longitude'] = $affiliate->mapmarker->lng;
$marker['title'] = $affiliate->title;
$data['markers'][] = $marker;
}
print(json_encode($data));
The problem here is that $affiliate->title returns an object (LanguagesPageFieldValue), instead of the actual string I would expect it to do.
I'm not sure where I'm going wrong here. I may have to manually set the language, call the title in a another manner, or just use a different approach alltogether. Any help is much appreciated