Skip to main content
19 events
when toggle format what by license comment
Jun 15, 2020 at 8:21 history edited CommunityBot
Commonmark migration
Oct 1, 2012 at 19:11 vote accept mathiregister
Sep 28, 2012 at 20:20 comment added Adam let us continue this discussion in chat
Sep 28, 2012 at 20:12 comment added Adam @mathiregister I've removed strtotime() from the $text variable in my example above. This formats the date in a human readable form. So continue storing your values as 'type' => 'text_date_timestamp' then (as you wish), then when running your query you sort by the meta_key you have set for that value. This works.
Sep 28, 2012 at 20:10 history edited Adam CC BY-SA 3.0
deleted 11 characters in body
Sep 28, 2012 at 18:14 comment added mathiregister And what I don't get either is when I'm testing for isset($_POST['wr_event_end_date'])? inside my save_details() function and call a die('event-end-date is set!);` and leave the field blank it still dies! So even though the field is empty (and nothing should be set to the field) the condition is true! Why is that? Nothing is getting saved to the database but the condition is true – see my update above!
Sep 28, 2012 at 18:12 comment added mathiregister Ok, thank you but I still don't get it. Please bear with me. I do have it set as text_date … but I'm converting it to a timestamp when I save it to the database! I need to do so, because I'm sorting my events by this timestamp and can't do it with a fully formatted date. I completely got rid of my update_post_meta() function for the "event_end_date" but nothing is getting saved to the database automatically!? Are you sure this is saved automatically. I'm inspecting ma database table after I save the event-end-date field but nothing is in the db.
Sep 28, 2012 at 17:41 history edited Adam CC BY-SA 3.0
added 968 characters in body
Sep 28, 2012 at 17:28 comment added Adam @mathiregister Please refer to my update. You are going about this the long way round. Revert back to using 'type' => 'text_date' and then use the in built WordPress Date handling functions to format your output as desired. (link to Codex resource in answer above).
Sep 28, 2012 at 17:27 history edited Adam CC BY-SA 3.0
added 968 characters in body
Sep 28, 2012 at 16:10 comment added mathiregister … I need to convert this timestamp back to a german date like "25. September 2012" … And that's why in this case I need the save_details() function for this particular field. I just need to find a way not to create and save a timestamp when the value of the input is empty. Does that sound complicated?
Sep 28, 2012 at 16:08 comment added mathiregister Ok, thank you. However the real problem in my case might be that I 'type' => 'text_date', as the input for my event_end_date field and then I'm converting it to a timestamp! And I need to convert it to a timestamp because I need to parse it as a german date on the frontend. I know there is also a field type of the library that provides a timestamp. However I want my backend to use german date formatting when I select a date in the date-picker. When saving the date I want to convert it to a timestamp (because I need this value for sorting stuff) and inside my get_event_end_date() function
Sep 28, 2012 at 16:08 comment added Adam I suggest temporarily removing (commenting out) your save_details function as shown in your link above and experiment with the meta box in question to see how the library natively handles the the input data for you by default.
Sep 28, 2012 at 16:03 comment added Adam Unless you have the need to do something else with the data prior to saving it WHICH does not consist of simply saving it as you entered it within the post edit screen, then I do not see the need for a custom function hooked onto the save_post action because the library handles the saving of data for you already. Refer to init.php. Your custom function to retrieve the post meta is on the other hand OK because it may serve your need to customize output or simplify a verbose process.
Sep 28, 2012 at 15:57 comment added mathiregister Well, I'm kind of confused now. I don't need to save the details of the meat-boxes? I didn't know that the lib handles this as well … see a snippet of my code … cl.ly/code/2F2B2R102B3P … I save all the details for my custom post type with update_post_meta() and retrieve them via a custom get_event_something() function. Can you provide a little update on how I really do that with the library? Thank you in advance!
Sep 28, 2012 at 14:35 comment added Adam Where are you placing your update_post_meta function and are you trying to save values from a front end form? If you're not, then you really don't need to have an update_post_meta function because the meta box library you are using handles the saving of fields and their values when in the post edit screen. So instead you should only enter a value if you want to, if not, then the field will remain blank until you provide a value.
Sep 28, 2012 at 14:23 history edited Adam CC BY-SA 3.0
added 417 characters in body
Sep 28, 2012 at 14:17 comment added mathiregister Oh, wow, this must be it. But I'm pretty new to php, how can I make sure it is only save if there is a value in the box?
Sep 28, 2012 at 14:10 history answered Adam CC BY-SA 3.0