OK, I’m taking on the dreaded task of developing an event calendar for my site and have gotten a bit stuck. I’m open to any and all ideas but here’s what I’m doing and what I’d like to do. I’m assuming that my main issue is the order of hooks and filters because i feel like I have a pretty good grasp on what I want to do. Also, I’d stick to wordpress hooks and filters rather than direct mysql database manipulation.
The short is…
- Save the first custom field and then change the current post_date to that custom field and change post_status to future, in that order, whenever a post is saved as draft or submitted for review.
- Take the second custom field and insert a new post with that custom field as the date of the new post and change the post_status of the new post to ‘future’ and copy the title, content to that new post from the original post. (goal is to create an identical new post for each date submitted on the original post, make the new posts childs of the original post, and schedule them all as future posts)
Now on to the long version.
First, i have a custom post_type called ‘events’. Registered for that I have some custom fields which for simplicity we’ll call _start_date_one, _end_date_one, _start_date_two, _end_date_two.
What I’d like to do is allow an ‘events’ post to be created and allow input of these fields, a title, and content. So far so good. Then when someone clicks “Save Draft” or “Submit for Review” I’d like to change the current post_date to _start_date_one and change the post_status to ‘future’. Right now I can get this to occur only after the at least the second time I save most likely because I’m using
add_action(‘save_post’) to save custom fields
and then
add_filter(‘wp_insert_post_data’) to update current post data
I realize through some trac searching that insert_post_data happens prior to saving to allow me to update the $data and $postarr with new info and then saves the custom fields which is why the above happens.
Number 2 listed above I’ve tried quite a few ways to get wp_insert_post to work but have only gotten to inserting a pending post with none of the dates correct and everything else copied.
Any help is greatly appreciated.
Hi @user2271:
I recently had to resolve a situation for an Event custom post type where I could not get WordPress to let me save a future date. I wasn’t trying to be as complex as yours but the follow code resolved my issue, maybe you can use it to resolve yours:
Basically WordPress is applying blog post logic to all posts and events should follow different logic. The code I’ve posted grabs the incoming date in the
'admin_init'
hook and then reuses it in the'wp_insert_post_data'
hook after WordPress has “fixed up” the dates per blog post logic.Understanding this issue I think will help you determine how to fix as per your more complex workflow?
Hope this heps.