Publish a post via API
-
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?
The topic ‘Publish a post via API’ is closed to new replies.