WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] building an events object (20 posts)

  1. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    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/

  2. agelonwl
    Member
    Posted 1 year ago #

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

  3. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    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.

  4. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    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.

  5. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    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.

  6. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    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();
  7. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    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

  8. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    I should say i got some help ;)

  9. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    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

  10. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

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

  11. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    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?

  12. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    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!

  13. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

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

  14. dradovic
    Member
    Posted 1 year ago #

    @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!

  15. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    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.

  16. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    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.

  17. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    ah, start/end aren't populated first time round. However, they should be next time the object is loaded from the DB.

    I thought you meant _start_ts/_end_ts which is stored as post meta in the wp_postmeta table.

  18. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    No i did mean the start_ts and end_ts weren't being stored properly, but isnt the value that gets stored just the $start and $end variables? regardless, thats how i got it to work and i am now pushing the limitations of my knowledge and im quickly going to get lost! Thank you once again for all of your help.

  19. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    :)

    thanks for disagreeing, I looked again and actually, you have a point here...

    $EM_Event->start/end are used to save _start_ts/_end_ts but since they aren't defined until you load a saved post (or save using get_post), it won't work here, so you've actually caught me out here, you DO need to save those two values!

    e.g.

    $EM_Event->start = strtotime($EM_Event->event_start_date.' '.$EM_Event->event_start_time);
    $EM_Event->start = strtotime($EM_Event->event_end_date.' '.$EM_Event->event_end_time);
  20. neiloliverphoto@gmail.com
    Member
    Posted 1 year ago #

    Well i am glad i could at least gig something small back. Big smile on my face for not being stupid.

    Thanks again

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic