• Resolved filipfek

    (@filipfek)


    Hi!

    In my opinion, I have a rather strange problem with The Events Calendar. I want to add an event via code(API). For example, I create a custom ACF field ‘eventbim_publish’, create an event and in this event I set this field as ‘publish’. The status of the post is ‘pending’, when I refresh the event and the value of ‘eventbim_publish’ is ‘publish’ then I want wordpress to change the event from pending to publish. I have my own code:

    function eventbim_auto_publish_event($post_id) {
    if (get_post_type($post_id) !== 'tribe_events') {
    return;
    }

    $publish_flag = get_post_meta($post_id, 'eventbim_publish', true);

    if ($publish_flag === 'publish') {
    remove_action('save_post_tribe_events', 'eventbim_auto_publish_event');

    wp_update_post([
    'ID' => $post_id,
    'post_status' => 'publish'
    ]);

    update_post_meta($post_id, 'eventbim_publish', 'published');

    add_action('save_post_tribe_events', 'eventbim_auto_publish_event');
    }
    }
    add_action('save_post_tribe_events', 'eventbim_auto_publish_event');

    Generally it works, the event changes status from pending to publish and displays published, the only problem is that the event is not visible on the website…When I go to the post edit, click ‘Update’ without making any changes, the event is visible on the page. As Events Calendar requires manual approval to publish?

    My code requires refreshing the post in Events Calendar? Please help so much, I can’t manage it 🙁

    https://theeventscalendar.com/knowledgebase/introduction-to-the-events-calendar-rest-api/

    Here is explained how to add an event through the API, which I do by setting “status”: “publish” – however, as I described above, at the very end I have to manually click “Update” to make the post visible, even though its status is “publish”. Is some plugin function responsible for this?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter filipfek

    (@filipfek)

    In wp-admin everything looks correct, however, I additionally checked the database. The post adds correctly to the _posts table – everything looks correct. However, the event information is not in other tables like _tec_events. That is, as if the post was not added in Events Calendar. When I click “Update” in wp-admin, everything is already working correctly, and there is an additional entry for the event in _tec_events. The problem is that I don’t know how to solve this and I don’t know why the post doesn’t add to Events Calendar by default…. I will be very grateful for help 🙁

    Plugin Support Darian

    (@d0153)

    Hi @filipfek

    I’m glad you reached out. Let me help you with this one.

    Our plugins use custom tables, so if you’re importing or creating events through a third-party plugin, it’s likely treating them as regular posts without adding the necessary entries to our custom tables.

    To fix this, try resaving the event using TEC’s ORM API with the ->save() method:
    TEC ORM API Documentation

    I hope this helps. Let me know if you have further questions or concerns.

    Thread Starter filipfek

    (@filipfek)

    Hi @d0153

    thank you for your reply. I understand the idea, however I still can’t figure it out. I replaced the code from wp_update_post to tribe_events, but it is still not saved as Event…. 🙁

    FROM
    wp_update_post([
    'ID' => $post_id,
    'post_status' => 'publish'
    ]);

    CHANGED TO
    tribe_events()
    ->where('post_id', $post_id)
    ->save();
    Plugin Support tristan083

    (@tristan083)

    Hi @filipfek ,

    Thank for your message, and I’m sorry to hear of the difficulties.

    To help us better understand the situation, could you please get back to us with more information about how you are creating events or sending events via API to your WordPress site?

    Plugin Support Darian

    (@d0153)

    Hi @filipfek

    I hope you’re doing well. I just wanted to touch base and check in with you. It’s been a little while since we’ve heard from you. I was just curious if you had the chance to review the response above.

    Let me know if there’s anything I can assist you with.

    Thread Starter filipfek

    (@filipfek)

    Hi!

    I very much appreciate your will to help, but to be honest I gave up, because I lost too much time on it… I just add by API Call custom post type which is tribe_event and I can’t save it, as tribe_event. I have decided that the safest solution is to have everything saved correctly as tribe_events, just manually publishing in WP Admin….

    Plugin Support Darian

    (@d0153)

    Hi @filipfek

    I found a related issue, and one of my colleagues recommended to use this function instead: tribe_update_event()

    https://docs.theeventscalendar.com/reference/functions/tribe_update_event/

    I hope this helps. Let me know how it goes.

    Plugin Support Darian

    (@d0153)

    Hi @filipfek

    I hope you’re doing well. I just wanted to touch base and check in with you. It’s been a little while since we’ve heard from you. I was just curious if you had the chance to try out the recommendation provided above.

    Let me know if there’s anything I can assist you with.

    Plugin Support Darian

    (@d0153)

    Hi there,

    It seems like this thread has been quiet for a bit, so we’ll go ahead and mark it as resolved. However, if any further questions or concerns come up, please don’t hesitate to start a new thread.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Publish a post via API’ is closed to new replies.