Posting event with a gravity form.
WordPress Event Management, Calendars & Registration › Forums › General Question › Posting event with a gravity form.
This topic contains 30 replies, has 5 voices, and was last updated by Stephen Harris 10 years, 9 months ago.
-
AuthorPosts
-
January 3, 2013 at 9:22 pm #2845
I need to allow frontend event posting and want to use a gravity form with some custom fields. It looks like this will not be easy to do with how the data is stored.
I just need the dates (start end) and if no start/end time a check for an all day event. If the event organizer wants a reoccurring I will have them contact me to set that (so it is not abused from the front end). I believe I have working code to change gravity’s date to a unix time (but it only has date no time) as I think this needs to happen.
Could anyone shed some light on how I could do this?
Michael
January 4, 2013 at 2:16 pm #2851Hi Michael,
I’ve not used Gravity Forms (though I believe some people have used it with Event Organiser). For the front-end posting you might find the following useful: http://www.stephenharris.info/2012/front-end-event-posting/
I believe Gravity Forms allows to you to add various fields (including date and time fields) and provides hooks so you can process form submissions. From that you can take the date/time submissions and convert it to a DateTime object required by
eo_insert_event()
.I’m not really able to help with the Gravity Forms part – but if you’re able to pastebin some code, I’ll be able to give a few pointers on integration with EO. Most of what you need to know is in the linked article though.
Stephen Harris
January 4, 2013 at 4:44 pm #2853I forgot about that article I taken in so much in the last few months. I’ll see what i can come up with.
Michael
January 5, 2013 at 8:11 am #2858Hi Stephen
Here is a Pastebin with what I’d hoped would work but alas my php skills…well they suck frankly.
I’ve no problem believing this is all wrong because I can’t make it work.Michael
January 5, 2013 at 8:34 am #2859Ok so it does work sort of but…
I get double posts one made by the gravity form and one from EO.
The post EO creates adds new venue with a number for a name and with the dates set but it’s also set to a draft.
The gravity post has the right venue and category but no dates (this I knew) I’ve to find a different gravity hook maybe.Michael
January 5, 2013 at 5:24 pm #2861So this Pastebin fixes the double post. I just have to get the venues to save the name rather then id.
eo_insert_event seems to be setting my event to drafts. How can I change this?Michael
January 5, 2013 at 7:31 pm #2862I’m sorry for filling your forum “thinking out loud”. But just keeping the progress updated maybe my noobness will help other wanting to do this.
Fixing the post status was easily done usingwp_insert_post args ('post_status'=>'publish',)
plus I learned I can usewp_strip_all_tags()
to clean the title and content as I needed.I still can not work out the venue. I can set the category without problem but the venue always returns the ID.
I have the ID stored in$entry['5']
and don’t know how to get the name.
I tried adding this$event_venue = (int) isset($entry['5']) ? $entry['5'] : 0;
but it still gives the ID in'event-venue'=>array($event_venue),
.Michael
January 5, 2013 at 8:47 pm #2863One last thing I can not seem to work out also is how to keep my custom field data from the form when using
eo_insert_event()
.These two things (venue issue above and this) and I am all set to relaunch our site. I am one week late and sooo want to get this off my plate (this is where all my desperation is coming from).
Michael
January 6, 2013 at 2:55 pm #2868Hi Michael – no worries, I’m sure many others will find this thread useful.
Post Status
The first argument in
eo_insert_event()
(see docs) is passed towp_insert_post()
(see codex). So anything like setting the event status (publish, draft) etc can be done by setting thepost_status
argument as appropriate.$post_args = array( ... 'post_status' => 'publish' ... );
Venues
I take it you are selecting an existing venue, and not creating a new one? If so, you need to pass the venue ID (as an integer). If its not an integer then its interpreted as a slug, and since it probably doesn’t exist, it’ll create a new one:
$venue_id = (int) $entry['5']; $post_args = array( ... 'tax_input'=>array( 'event-venue'=>array($venue_id), 'event-category'=>$entry['4'], ), ... )
Custom Data
Is this custom data post meta? If so,
eo_insert_event()
returns the event’s post ID, so you can simply use WordPress’update_post_meta()
from there (see Codex)Stephen Harris
January 6, 2013 at 6:35 pm #2873Sweet! Thank you so much, venues set right and my custom fields are included.
How can I set a featured image from my upload field? I’ve just begun looking into this bit now.
Michael
January 6, 2013 at 9:50 pm #2875When I let gravity handle inserting the post it would move the uploaded image and set it as featured. Because I have disabled it creating the post, how can move and attach the image stored in
($entry['3']
(full path) to my event.If I add this
$url = $entry['3'];
$tmp = download_url( $url );
$desc = "Event Image";
// Set variables for storage
// fix file filename for query strings
preg_match('/[^\?]+.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
// If error storing temporarily, unlink
if ( is_wp_error( $tmp ) ) {
@unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
// do the validation and storage stuff
$id = media_handle_sideload( $file_array, $post_id, $desc );
// If error storing permanently, unlink
if ( is_wp_error($id) ) {
@unlink($file_array['tmp_name']);
return $id;
}
$src = wp_get_attachment_url( $id );
set_post_thumbnail( $post_id, $src );
After submitting my form it hangs and does not complete and redirect as it should. The post is made but the is not attached.
I have tried several thing but no luck with this thus far.
Michael
January 6, 2013 at 10:31 pm #2877The second argument of
set_post_thumbnail()
takes the thumbnail ID rather than src value.Alternatively, if Gravity forms provides a hook after creating the post, you can always use
eo_update_post()
(see docs) to add the event details, and do it that way round…Stephen Harris
January 7, 2013 at 1:42 am #2878Looks like I can only hook and change the post before it is created and not after. Unless I can add EO’s data to it’s custom field
_eventorganiser_event_schedule
some how. I triedeo_update_post()
but no dates saved.Maybe I can work out a different way to add an image from a custom field. I just want to delete the image when the event is deleted.
Michael
January 7, 2013 at 9:02 pm #2890Don’t touch the meta value
_eventorganiser_event_schedule
directly (other things need to be done!).Sorry, its
eo_update_event()
noteo_update_post()
. If it doesn’t seem to work – have a look at what its responding with. It should work if the post is an event (but obviously post will need to exist!).I just want to delete the image when the event is deleted.
Hook onto
before_delete_post
( http://queryposts.com/function/wp_delete_post/ ) and get the thumbnail image ID and then usewp_delete_attachment()
.Stephen Harris
January 12, 2013 at 5:46 pm #2952I had to take a break. Things have been hard then I thought.
I did use
eo_update_event
and noteo_update_post
. If I let gravity make the post and useeo_update_event
the event details are not added to the post.I will make a feature request in the right spot.
Michael
-
AuthorPosts