Skip Navigation

[Closed] WP Grid Builder Map Issue

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by Shane 1 year, 10 months ago.

Assisted by: Shane.

Author
Posts
#2389227

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
);

#2394657

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

#2403533
aa see here.png

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?

#2403631

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

#2403647

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

#2403649

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

#2403663

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

#2403677

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?

#2403785

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

The topic ‘[Closed] WP Grid Builder Map Issue’ is closed to new replies.