I have two custom fields in my article for longitude and latitude. I'm then trying to build a module to get these two fields from the current article displayed and show in the module.
I have the following but it's not working:
<?php
$id = $item->id;
$db = JFactory::getDbo();
$query = 'select * from #__fields_values where item_id = "'.$id.'"';
$db->setQuery($query);
$fields = $db->loadObjectList();
foreach ($fields as $field) {
var_dump($field->value);
}
?>
It's not even showing when using var_dump
Ideally, I'd like to create the variables in the foreach and assign $latitude and $longitude a value (from the article custom field)
#__fields_values
). If they don't help, please create a db-fiddle with some sample rows and I'll spin up a query for you. Out of curiosity, does$item->id
contain the expected value when you test your script?