Custom fields: Split data from single custom field’s sub-array to separate custom fields when saving post


TLDR; I’m using a plugin that stores its data in a sub-array, and I would like to save data from the sub-array to separate custom fields when a post gets saved.

In my case, it’s a plugin that shows a map on the edit screen of a post where you can add one or more markers by looking up an address, and it stores – among other data – the longitude and latitude data of the marker(s) into a sub-array. The first array is the markers one because you can add more than one.

Is there a way to get the first marker, its lat and long values and save them to separate custom fields when a post gets saved? Since values can change, I think the most clever way would be to save or update the lat/long fields upon saving a post. I only really need the first marker at any given time.

So the structure that the plugin creates would be like this (map is the custom field’s name):

map {
    markers {
        [0] {
            'lat' => '1234',
            'long' => '5678'

physalis 2 months 2022-10-12T05:59:06-05:00 0 Answers 0 views 0

Leave an answer