I have a custom post type that has custom fields as meta data.

The post is a lesson. As part of a lesson I have a webinar_id field.

I typically don't edit that field directly, though I could if needed. So in admin editor I have that field displayed and at first it is blank.

Then later I specify a time for the webinar (since I have a webinar_time meta field) and that triggers the creation of the webinar on www.zoom.us. I then populate webinar_id with the value that I get back from the Zoom restAPI.

Using wordpress save_post hook I am doing it this way:

add_action('save_post_sfwd-lessons', 'deal_with_zoom', 10, 3);

function deal_with_zoom($post_ID, $post, $update)

    // wordpress often calls save_post multiple times so only do something if real deal
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
    if (wp_is_post_revision($post_ID)) {
    if (wp_is_post_autosave($post_ID)) {
    // if new post
    if (!$update) {

    $times = did_action('save_post_sfwd-lessons');
    if( $times === 1){
        file_put_contents('/wp-content/debug.log', 'In Theme functions save_post hook ' . $post_ID . PHP_EOL, FILE_APPEND);

        // create webinar on zoom.us

        // first see if we already have webinar instance associated
        $zoomid = get_post_meta($post_ID, 'webinar_id', true);
        $zoomtime = get_post_meta($post_ID, 'webinar_time', true);

        // do some stuff with zoom RestAPI (create or update depending on if id already not null
        $zoomid = get from zoom response...
        // write the returned id from zoom in the database or id will be same as what was read earlier
        update_post_meta($post_ID, 'webinar_id', $zoomid); 

        // After this update I can't figure out how to populate the input field in the admin editor...


BTW - I notice via my logging my hook's actions (after all the checks) are being called twice even though I am doing all sorts of checks to make sure it is executed once, but that is a different problem...

So, in the wordpress admin area, this webinar_id field is initially empty. When I hit update, my hook runs, the value from Zoom restAPI is saved as meta data, but the field is not refreshed back in the editor. So when I get back to the editor, if I edit the post and hit update again, the webinar_id field is back to null. I suppose I have to pass a $_POST variable back after my hook or use AJAX in some fashion or some other built in jQuery function that accesses the value that my hook retrieved? If so, how?

Or maybe I should't use save_post at all and use update_post_meta hook? But that still has me wondering how to get the webinar_id set in my hook to populate the admin editor webinar_id input field after pressing update?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.