Hi there,
I have a load_field filter that I use to get data from a maps plugin (Mapsmarker Pro).
The filter populates a select field which grabs the ID and name of of each entry.
Existing Function:
<?php
add_filter('acf/load_field/name=map_marker', 'my_acf_mapsmarker_choices');
function my_acf_mapsmarker_choices($field){
$field['choices'] = array();
global $wpdb;
$results = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'leafletmapsmarker_markers ORDER BY ID ASC');
if(!empty($results)) :
foreach($results as $result) :
$value = $result->id;
$label = $result->markername;
$field['choices'][ $value ] = $label;
endforeach;
endif;
return $field;
}
?>
What I’d like to do is use the Select field value to then populate two additional acf number fields with the longitude and latitude entries (Field names ‘marker_lon’ & ‘marker_lat’. The values for these fields reside in the same DB Table under columns ‘lon’ & ‘lat’. E.g.
From what I can tell I need to use another load_field hook to target each number field. E.g.
<?php
add_filter('acf/load_field/name=marker_lat', 'rar_acf_mapsmarker_latitude');
function rar_acf_mapsmarker_latitude($field){
$field['value'] = '';
global $wpdb;
$results = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'leafletmapsmarker_markers ORDER BY ID ASC');
if(!empty($results)) :
//get the first value on the array
$value = $results->lat;
//update the field value
$field['value'] = $value;
endif;
return $field;
}
?>
This loads the first table entry but I’m struggling to figure out how to target the selected value from the original array to populate these number fields.
Does anybody have any experience with doing this sort of thing?
Any help would be great,
Many thanks!