Hi there,
We are trying to use hidden link
...with certain parts of our websites.
We use a Toolset custom field to add the longitude and latitude...they given us this code and said we need to adjust the code to our need.
Apparently we need to look at toolset doc how to get the field value and you need to inject them in the code.
We've no idea about php, any thoughts on where I find this or what I need?
Thank you.
add_filter(
'wp_grid_builder/indexer/index_object',
function( $rows, $object_id, $facet ) {
if ( empty( $facet['filter_type'] ) || 'map' !== $facet['filter_type'] ) {
return $rows;
}
return [
[
'facet_value' => 'latitude',
'facet_name' => 'longitude',
],
];
},
10,
3
);
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Pete,
Thank you for getting in touch.
The longitude and Latitude values are being store in separate custom fields like a single line field and not an address field correct?
If so then you can use the functions below to get the values in php.
types_render_field( "my-singlelinetext", array( ) )
Assuming that this function is triggered on the actual post then you can do this.
add_filter(
'wp_grid_builder/indexer/index_object',
function( $rows, $object_id, $facet ) {
$long = types_render_field( "longitude_field_slug", array( ) );
$lat = types_render_field( "latitude_field_slug", array( ) );
if ( empty( $facet['filter_type'] ) || 'map' !== $facet['filter_type'] ) {
return $rows;
}
return [
[
'facet_value' => $lat,
'facet_name' => $long,
],
];
},
10,
3
);
This is how you would get the values in PHP.
If this doesn't work please let me know as you may need to get the run context of the code from the WP Grid Builder support team.
Thanks,
Shane
Hi Shane,
The longitude and Latitude values are being store in a single line, please see attached.
So guess the code you kindly supplied wont work right?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Pete,
This isn't a single line field. It is an Address field. In such a case a different intervention will be required.
Is it that you are copying and pasting the exact longitude and latitude into the field in that exact format as the screenshot ?
Please let me know.
Thanks.
Shane
Hi Shane,
Each custom post: hidden link
...has its longitude and latitude added to a custom field as shown above.
Does this help at all?
Thank you
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Pete,
Actually no this doesn't help as i'm not sure if you're storing the longitude and latitude elsewhere or if its just being stored in the Address field as depicted by your screenshot.
Perhaps if I look at the post itself on the backend I would have a better Idea.
I've enabled the private fields for your next response.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Pete,
So you are storing the longitude and latitude directly. Here is the updated code.
add_filter(
'wp_grid_builder/indexer/index_object',
function( $rows, $object_id, $facet ) {
$coords = types_render_field( "address-area", array( ) );
$lat = 0;
$long = 0;
if(!empty($coords)){
$trimed_coords = explode(",",trim($coords,"{}"));
$lat = $trimed_coords[0];
$long = $trimed_coords[1];
}
if ( empty( $facet['filter_type'] ) || 'map' !== $facet['filter_type'] ) {
return $rows;
}
return [
[
'facet_value' => $lat,
'facet_name' => $long,
],
];
},
10,
3
);
Please let me know if this helps.
Thanks,
Shane
Hi Shane,
Thanks for checking this out. I am not great with this type of code, so am I adding this to, we use Code Snippets, exactly what you have added?
Just the above?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Pete,
That's correct, however i'm not exactly sure of the exact run context of the code. For this you will have to contact the support team for the plugin you're using.
Thanks,
Shane