- This topic has 3 replies, 2 voices, and was last updated 5 years, 6 months ago by
Steve.
-
AuthorPosts
-
-
July 16, 2016 at 11:22 am #6957
jacotheronMemberThe setup is very simple. I have a new custom post type, with a repeating field for dates (since this cpt can have a few dates associated with it), among the other fields.
I need to save these dates to separate post_meta lines, so that I can for example sort them by these dates (if it only have one date, it will be listed once, but if it have more, I need to have it listed for each date). I have no idea what the maximum number of dates will be, so making X amount of date fields are not going to work.
By default Piklist saves the repeating fields as a serialized array (which is good and very useful most of the time), but in this case I need them separate to reduce the load on the server (also enabling me to use a standard WP_Query query to retrieve all the posts, or the next 10 or so dates).
I am thinking of using the ‘piklist_save_field’ action hook to implement it (first making sure we are only saving this specific field to more post_meta rows). What is the best/recommended way to achieve this – while maintaining association with the original (if I update the dates with new values to replace the old values with new ones, deleting any unused ones and adding more if required)?
This can be useful for example building an event calendar (where the events can repeat on very specific dates) – it is the basics of what I need.
-
July 16, 2016 at 11:29 am #6958
SteveKeymaster@jacotheron– Welcome to the Piklist community!
If you use a simple repeater, not a group, then the data is saved as individual meta rows.
This is an example taken from the built-in demos:
piklist('field', array( 'type' => 'datepicker' ,'field' => 'demo_add_more_date' ,'label' => __('Date Picker', 'piklist-demo') ,'add_more' => true )); -
July 16, 2016 at 11:44 am #6959
jacotheronMemberHi Steve
I was looking in my database, but did not see it (until I now checked the post_id and there it was in 2 different lines). I had it a while now with the simple repeater (first I had it as a group, to also be able to add time, then I implemented the Webshim Date and Time function, using a custom field so that I have only one field per date).
Thank you very much and also for the very quick reply. I guess I am looking but not focusing anymore.
-
July 16, 2016 at 12:23 pm #6960
SteveKeymasterGlad I can help.
Piklist is designed to be flexible. We also built it so you can query on most fields… which is why we save repeater data as multiple lines in the db.
Closing ticket.
-
-
AuthorPosts
- The topic ‘Save addmore field to seperate post_metas’ is closed to new replies.