WordPress.org

Support

Support » Plugins and Hacks » Events Manager » [Resolved] building an events object

[Resolved] building an events object

  • neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    First let me start off by saying i love events manager. I am seriously blown away by the features and support, even on the free version.

    I am a bit of an amateur at all fo this so please forgive me if i misunderstand things or use the incorrect terminology.

    I am trying to add an event via PHP in a plugin that i am building. I know from searching the forums that i need to use EM_event->save() and that i need to build an events object, but i have no clue how i build this object.

    If someone could help me out that would be great, just showing me how i would build the object and how i call the EM_Events->Save from another php file.

    if you assume that i would be entering each of the values needed (ie Event Title) as a text value then i should be able to work out how to substitute that with the information i already have.

    Thank you so much in advance.

    http://wordpress.org/extend/plugins/events-manager/

Viewing 15 replies - 1 through 15 (of 19 total)
  • agelonwl

    @angelonwl

    someone in pro forums share this and this might help you also -> http://pastebin.com/3UDjZ8Le

    neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    Thank you for the speedy response. This is quite a similar idea to what i am trying to create, but i am only trying to create a single event at a time.

    Also, this doesn’t seem to use the events manager save function, what are the advantages / disadvantages of doing it manually / using the save function?

    Thank you once again, its so great that people take the time to help others out, especially when i am such a novice.

    Plugin Author Marcus

    @netweblogic

    NetWebLogic Support

    I wouldnt’ recommend using that if you don’t know what you’re doing and how EM works r.e. how data is stored. The user that submitted this does a lot of funky stuff with the plugin 🙂

    In a nutshell, you should look at how we do it by generating a public event form (e.g. using [event_form] and template file templates/forms/event-editor.php) and grabbing that info from $_POST using $EM_Event->get_post()

    that’s what loads the information into the event first before calling save(). You could also do this without submitting a form if you get the information from elsewhere.

    neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    Hi Marcus, Thanks for the reply. I have a friend helping me out who knows a bit more about it, so i will show him your reply and hopefully he can help me implement this.

    To clarify, the bit that i am trying to create at the moment will create an event using information that i have got from other sources. I have all of the required information waiting to be saved to the database and its using a pre existing location so that bits not too bad either. i understand how to manually store the information into the post, meta and events table, but i was just trying to search for a cleaner way of doing this, ie using the EM_Event->Save().

    Thanks again for your help. I will be writing a bit on our blog about the plugin and your support when we are up and running.

    Plugin Author Marcus

    @netweblogic

    NetWebLogic Support

    cheers, EM_Events would be the best way.

    I indicated get_post (and get_post_meta) because it adds all the relevant information to your EM_Event object. You could also do this directly e.g.

    $EM_Event = new EM_Event();
    $EM_Event->event_name = 'your event';
    //etc.
    $EM_Event->save();
    neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    Amazing, thats exactly what i needed! i was hoping it could be done that simply. Do i need to define every field or will the ones that need to be null etc already be filled? (does that make any sense!)

    Thank you so much for putting up with my ignorance. To boost myself up a bit, i know nothing about programming yet i have made a plugin that gathers geolocation information, searches events and grabs information from last.fm

    I am pretty pleased with myself.

    I cant wait to get this bit done.

    Thanks again

    neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    I should say i got some help 😉

    Plugin Author Marcus

    @netweblogic

    NetWebLogic Support

    i think I understand, any fields you don’t define specifically will be set to null or the default. The only ones I think you must have are:

    event_name
    event_start_date
    event_end_date

    neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    thats exactly what i meant. incredible, thank you. I will drop you a link when its done and launched.

    neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    so i am doing well, the instructions you gave were exactly what i needed. The events adds to the db, but in the admin events page the event isnt listed? The annoying thing is i only have two events listed and it says 3 are published. Also, when i manually found the edit event page for the added event (by changing the url to use the post id on the event) it found it perfectly, with all of the information listed, and when i clicked update, without changing anything, the event was then listed in the events admin page.

    It must be something simple. Any ideas?

    neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    I have identified the problem, its not saving the end_ts and start_ts properties correctly in the postmeta. not sure why or who i am meant to fix it.

    I bet this is sooo simple!

    neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    No worries, i either sorted it or made a work around. Thanks!

    dradovic

    @dradovic

    @neiloliverphoto: Can you share some code showing how to store a new event object? It is unclear to me how the event object is linked to its post and post_meta objects and how to instantiate and populate these.

    Your help would be very appreciated!

    Plugin Author Marcus

    @netweblogic

    NetWebLogic Support

    I’m not sure how neil solved that because the start/end meta values he mentioned are created in ->save_meta(), which is called after ->save(), so in theory what I mentioned above is a good start.

    neiloliverphoto@gmail.com

    @neiloliverphotogmailcom

    I am the worst person to ask! I am a total novice at this. I simply used the code Marcus put above and listed all of the details i had, ie the start and end date, title etc.

    $EM_Event = new EM_Event();
    $EM_Event->event_name = 'your event';
    //etc.
    $EM_Event->save();

    Exactly as above! You dont need to worry about where the information needs to go in the database, the $Em_Event->Save() does all of that for you. As Marcus said, you must have a minimum of the event name, start and end date for the event to create. The problem i encountered was that it didn’t create a few of the values for the post_meta (as they were created in a different function of the events manager) so i had to populate a few more variables, namely $start and $end.

    $EM_Event->start = strtotime($EM_Event->event_start_date." ".$EM_Event->event_start_time);
    
    $EM_Event->end = strtotime($EM_Event->event_end_date." ".$EM_Event->event_end_time);

    That probably shows me up for knowing nothing about this stuff, but it worked. I hope that makes some kind of sense. If not hopefully Marcus will be able to guide you.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘[Resolved] building an events object’ is closed to new replies.
Skip to toolbar