最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Saving an array of dynamic repeater data as post_meta

programmeradmin0浏览0评论

Looking for some Wordpress specific PHP help. I'm making a time sheet with employees listed and in/out for everyday of the week. I am pulling an ACF repeater row of employees from another page that the employees originally get added, easy enough. This page changes daily and my code should be able to accommodate new entries. When the page loads, it grabs the old array from post_meta. If the names pulled from the repeater already exists, skip and add new names. On the first load, all get added.

Then we're adding the names into an array ($settings_names) with extra fields i.e. Monday In, Monday out etc.

Then for each of the users in the array, I'm printing the Agent name (borrowed from the other ACF page) as well as Input fields representing the beforehand mention extra data fields. So far so good, this displays great.

Now I need to be able to enter times in those "extra" input fields and have them all save back to that array. Next time user comes back and loads the page, he should be able to se the previously inputed times, enter more time data and save again into the array.

So far the page pulls the repeater data as it should, displays as it should and I can enter times in the fields.

For testing, I can even add an "update_post_meta($post_ID, 'settings_name',$settings_names);" at the end of the page load and the array will fill one post_meta field with the entire array. No times added yet.

The fields are within Form tags and I have a submit button, but not sure how to do the update_post_meta so that the time inputs are saved.

So my trouble is, how do I get these individual rows of time data to save back into the array where they need to be, with each user?

I have found the 4th option for update post meta - $prev_value - Previous value to check before updating. If specified, only update existing metadata entries with this value. Otherwise, update all entries.

But I don't know if this works with the array.

Thanks for the help.

发布评论

评论列表(0)

  1. 暂无评论