Events Manager
[resolved] Inserting new event from plugin (2 posts)

  1. Miguel Sirvent
    Posted 2 years ago #

    Hi so I'm trying to create a plugin than creates new events based on the data I provide so to test I wrote a very simple plugin:

    Plugin Name: Pruebas
    add_action('admin_notices', 'pruebas');
    function pruebas(){
    	global $pagenow;
      if ( $pagenow == 'plugins.php' ){
    	$new_event = new EM_Event;
    	$new_event->event_name = "Inserted event test";
    	$new_event->event_start_date = '20/01/13';
    	$new_event->event_start_time = '20:00';
    	$new_event->event_end_date_date = '20/01/13';
    	$new_event->event_end_time = '23:00';
    	$new_event->post_content = 'This is the content of an inserted post';
    	$new_event->post_status = 'draft';
    	$new_event->location = new EM_Location();
    	$new_event->location->location_name = 'New test place';
    	$new_event->location->location_address = 'Lerdo 201';
    	$new_event->location->location_town = 'Toluca';
    	$new_event->location->location_country = 'mexico';
      	echo 	'<div class="updated"><pre>'.$new_event->save() ? print_r($new_event) : printf('Fail Save') .'</pre></div>';

    The created event shows on the front end but not the admin, and the post_status is wrong it is supposed to be draft but it saved as publish, and location also don't work as expected. Any ideas?


  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    i think you also need to add event_status=0

    aside from that it looks like it should work. did you check your php error logs and your wp_posts table? Might be worth trying with WP_DEBUG turned on too.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Events Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic