Custom Save Post interferers with Venue saving

WordPress Event Management, Calendars & Registration Forums General Question Custom Save Post interferers with Venue saving

This topic contains 5 replies, has 2 voices, and was last updated by  Stephen Harris 9 years, 9 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #11622

    Hi,

    I have created a script that automatically creates an excerpt after saving/publishing the post. It also includes the event’s information. There is a problem that when you create a post, add a NEW venue inside that post, and when you click on Publicize, the post saves but venue is not added. The venue gets saved so I can add it to the post after first saving, but not at first. I did some testing and I am 100% sure it is this code that does this.

    I thought the add_action priority would be the problem but after testing both low and high priority numbers, it wasn’t that case and I couldn’t find any other solution.

    So I wanted to ask you if you wouldn’t have some idea what in the code could interfere with yours.

    Code http://pastebin.com/TBg2haww

    Thanks,
    Mark

    Marek Zelezny
    #11623

    Hi Marek

    the post saves but venue is not added.

    Do you meant the venue details are not added to the excerpt, or that the venue is not linked with the event at all?

    Regardless, you are using save_post with “priority” 10 (same as Event Organiser uses), so it’s possible that your script is firing before the venue is created and assigned to the event. You could just bump up the priority to 15 (I know, sounds weird, increasing the priority puts you further back in the queue ;)).

    Alternatively you can use the hook eventorganiser_save_event. This is broadly identical to the save_post hook, except it only fires for events.

    Stephen Harris
    #11628

    I meant that when you add a new venue in this field
    enter image description here

    Then when you hit Publicize, the new venue is not added to the post but is only saved to database. I have to select it again, hit update post and then it is associated with the post.

    The priority change didn’t work. The code looked like this:

    add_action('eventorganiser_save_event', 'mz_create_event_excerpt', 15, 2);

    I did little testing if some parts of the code don’t cause it and it seems it is this part

    if ( ! wp_is_post_revision( $post_id ) ){
    
        // unhook this function so it doesn't loop infinitely
        remove_action('eventorganiser_save_event', 'mz_create_event_excerpt');
    
        // update the post, which calls save_post again
        wp_update_post(array('ID' => $post_id, 'post_excerpt' => $result));
    
        // re-hook this function
        add_action('eventorganiser_save_event', 'mz_create_event_excerpt');
    }

    I think the remove_action function prevents the venue being added to the post but I couldn’t find a workaround because without this piece of code, the excerpt is not created. I also tried eo_update_event with same attributes, no results (also the eventorganiser_save_event).

    Marek Zelezny
    #11631

    Ah, I think I know what’s happening. The wp_update_post() (similarly eo_update_event()) is causing event organiser’s callback to fire again. The second time, it fails to create the ‘new’ venue (as it already exists). However, because the venue fails to be created, the venue ID is set to null, and this has the effect of removing any existing association with a venue.

    I’ll double check that this is actually what’s happening, and if so, implement a fix for the next release.

    Stephen Harris
    #11632

    A fix has been implemented and verified: https://github.com/stephenharris/Event-Organiser/issues/202. Due for next release.

    Stephen Harris
    #11941

    This fix was implemented in the 2.8.3 release.

    Stephen Harris
Viewing 6 posts - 1 through 6 (of 6 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.