Home Forums General Issues Update post status on edit


Update post status on edit

  • I have two forms on the front end:

    1- For creating a post and setting its status to ‘pending’
    2- For looking at existing posts with status ‘pending’, these can then be edited and/or just saved

    My issue: when I try to publish on form 2, I have the post status set to ‘publish’ this does not override the post status.

    I have found some previous code for this and it works, however it overrides the status to ‘publish’ for form 1 as well.

    Is there a way I can make this code run only for form 2 only?

      function my_pre_save_post($post_id) {
        // check for numerical post_id and check post_type
        if (!is_numeric($post_id) || get_post_type($post_id) != 'post') {
          return $post_id;
        // update status to publish
        $post = array(
          'ID' => $post_id,
          'post_status'  => 'publish' ,
        // update the post
        return $post_id;
      add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
  • I worked out how to do this by adding the following code at the top.

    This returns if the page is not the required page:

    if (!is_page('page-slug')) {
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.