WordPress.org

Ready to get started?Download WordPress

Forums

The Events Calendar
[resolved] Venue and organizer get wrong post_type when updating event (9 posts)

  1. Ulrich Christensen
    Member
    Posted 1 year ago #

    I have a problem where the venue post and the organizer post get the wrong post_type, when the event post is updated. Hence they show up in the list of events, because they are now "tribe_events" instead of "tribe_venue" and "tribe_organizer" respectfully.

    I have tried setting the correct post_type explicitly in the wp_update_post call in the updateVenue and updateOrganizer methods of TribeEventsAPI, but to no avail.

    In a possibly related issue, I've been experiencing an infinite loop in method addEventMeta(...) . I've avoided this by inserting a line:
    remove_action( 'save_post', array( $this, 'addEventMeta' ), 15, 2 );
    just before the call to TribeEventsAPI::saveEventMeta(...) .
    Venue and organizer being set to be "tribe_events", it would explain the looping. In any case I think it is safe to insert this line to avoid looping. I've added the action hook back after the call.

    Using version 2.0.8

    http://wordpress.org/extend/plugins/the-events-calendar/

  2. Alex
    Member
    Posted 1 year ago #

    this is how its working for me

    add_action('save_post', 'save_tec_event_meta_from_gravity', 11, 2);
    	function save_tec_event_meta_from_gravity($postId, $post) {
            if( class_exists('TribeEvents') ) {
            // only continue if it's an event post
            if ( $post->post_type != TribeEvents::POSTTYPE || defined('DOING_AJAX') ) {
                return;
            }
            // don't do anything on autosave or auto-draft either or massupdates
            if ( wp_is_post_autosave( $postId ) || $post->post_status == 'auto-draft' || isset($_GET['bulk_edit']) || $_REQUEST['action'] == 'inline-save' ) {
                return;
            }
    
            if( class_exists('TribeEventsAPI') ) {
                $_POST['Organizer'] = stripslashes_deep($_POST['organizer']);
                $_POST['Venue'] = stripslashes_deep($_POST['venue']);
    
                if( !empty($_POST['Venue']['VenueID']) )
                    $_POST['Venue'] = array('VenueID' => $_POST['Venue']['VenueID']);
    
               if( !empty($_POST['Organizer']['OrganizerID']) )
                   $_POST['Organizer'] = array('OrganizerID' => $_POST['Organizer']['OrganizerID']);
    
                TribeEventsAPI::saveEventMeta($postId, $_POST, $post);
    		}
    	}
    }
  3. joycegrace
    Member
    Posted 1 year ago #

    Hello uchristensen and Alex,

    This is very strange, I haven't heard of this before. Are you saying you had to modify the code to get it not use the wrong post type? If this is a bug in our system we should definitely have it logged! Had you made any other modifications before this one?

  4. Ulrich Christensen
    Member
    Posted 1 year ago #

    I've solved my problem with a possibly ugly hack in both TribeEventsAPI::updateVenue and TribeEvents::updateOrganizer. I simply do a query with $wpdb to update the post-type after the call to wp_update_post to ensure that the post-type is correct.

    Example:

    public static function updateVenue($venueId, $data) {
      	wp_update_post( array('post_title' => $data['Venue'], 'ID'=>$venueId) );
    	TribeEventsAPI::saveVenueMeta($venueId, $data);
    	global $wpdb;
    	$sql = "UPDATE $wpdb->posts SET post_type = '".TribeEvents::VENUE_POST_TYPE."' WHERE ID = '".$venueId."'";
    	$wpdb->query($sql);
    }

    I have no idea as to what is the cause of the wrong post type.

  5. Ulrich Christensen
    Member
    Posted 1 year ago #

    The errors occurred before I made any modifications.
    It looped infinitely when I tried to publish an event, and both Venue and Organizer entries showed up in the list of events.

    I added the lines to remove and reinsert the "save_post" action "addEventMeta" to solve the infinite looping inside the method addEventMeta around the call to TribeEventsAPI::saveEventMeta.

  6. Ulrich Christensen
    Member
    Posted 1 year ago #

    The whole Venue and Organizer entries showing up as events caused me quite a headache, since the person posting the events accidentally removed all the Venue and Organizer entries, because they looked like errors.

    This, of course, results in the name of the Venue and the name of the Organizer to not show up, but all the other data shows up fine, because it is in the "postmeta" table.

    It would be nice, if the Venue and Organizer posts would be re-created, if they are missing.

  7. joycegrace
    Member
    Posted 1 year ago #

    Hello uchristensen, I am having a higher level support person take a look at this.

  8. Ulrich Christensen
    Member
    Posted 1 year ago #

    I've found the culprit, which is an aptly-named plugin called "Post Type Switcher". That plugin is meant as an easy way to change the post type of the post you're editing, but seeing as it reads the post type to use from its own variable in the $_POST superglobal, it forces the associated posts Venue and Organizer to have their parent's (TribeEvent) post type. Ironically enough that plugin was super-helpful in fixing problem posts.
    That plugin really does, what it is supposed to (albeit too well), so it is not a problem to fix on that end.

    Going forward to avoid similar problems I think you should either explicitly set the post type after the call to wp_update_post in TribeEventAPI::updateVenue (and TribeEventAPI::updateOrganizer) :
    set_post_type($venueId, TribeEvents::VENUE_POST_TYPE);
    or use a call which doesn't call action hooks to update these associated posts, when called from an TribeEvent post.

    Alternatively, would it not be possible to store the meta-data with the TribeEvent post (by making VenueId and OrganizerId point to the TribeEvent post's postId)? It would of course involve using the meta-data field for Venue name and Organizer name instead of their respective post_title.
    This would get around the problem with the wrongly deleted associated posts.

  9. jonahcoyote
    Member
    Posted 1 year ago #

    Hi Ulrich,

    We plan to implement your suggestion in the next release. No ETA when that will be but it will be done. Thanks for your contribution and reporting this!

    Cheers,
    Jonah

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic