Home Forums ACF PRO Save edited post as pending / add acf field title Reply To: Save edited post as pending / add acf field title

  • Hi @beee

    You can show the post title field to allow for creating/editing that using post_title => true in acf_form().

    To change the post status after a submission of updating an existing post you should use the acf/save_post action hook. You could update it using wp_update_post() and if you do you HAVE TO remove your acf/save_post action before and add it back afterwards. Otherwise you’ll end up with an infinite loop.

    Another way is to change it using the global $wpdb variable directly.

    global $wpdb;
    //Skip if this isn't a post or if status is already pending.
    if ( ! $post = get_post( $post_id ) ) return;
    if ( 'pending' == $post->post_status ) return;
    //Update DB with pending status.
    $wpdb->update( $wpdb->posts, array( 'post_status' => 'pending' ), array( 'ID' => $post_id ) );
    //clean the cache for the post
    clean_post_cache( $post->ID );
    //Trigger all transition hooks in wordpress (in case other functions hook into those to do things.
    $old_status = $post->post_status;
    $post->post_status = 'pending';
    wp_transition_post_status( 'publish', $old_status, $post );