Support

Account

Forum Replies Created

  • Everything worked, did like this. Thanks for the help.

    function my_pre_save_post($post_id) {
      
        if (!is_numeric($post_id) || get_post_type($post_id) != 'task') {
        return $post_id;
        }
    	global $current_user;
        wp_get_current_user();
    	$userid = $current_user->ID;
    	if( is_page( 21 ) ){
    		$post = array(
    			'ID' => $post_id,
        		'post_type' => 'task',
        		'post_status'  => 'inwork' ,
        		'meta_input' => array('task_worker' => $userid, 'task_result' => ''),
        		);
    	$post_id = wp_insert_post($post); 
        wp_update_post($post);
    	}
        if( is_page( array(14, 82) ) ){
    		$post = array(
    			'ID' => $post_id,
        		'post_type' => 'task',
        		'post_status'  => 'pending' ,
        		);
    	$post_id = wp_insert_post($post); 
        wp_update_post($post);
        }
        
        return $post_id;
      }
      
      add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
  • Thanks for the answer. Everything worked, only with acf/pre_save_post, not acf/save_post.
    The code from the functions.php

    function my_pre_save_post($post_id) {
      
        if (!is_numeric($post_id) || get_post_type($post_id) != 'task') {
        return $post_id;
        }
    	global $current_user;
        wp_get_current_user();
    	$userid = $current_user->ID;
        $post = array(
        	'ID' => $post_id,
        	'post_status'  => 'inwork' ,
        	'meta_input' => array('task_worker' => $userid, 'task_result' => ''),
        );  
    
        $post_id = wp_insert_post($post); 
        wp_update_post($post);
        
        return $post_id;
      }
      
      add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );

    Prompt, and how to make if buttons two? The button whose code is given above changes ‘post_status ‘to’ inwork ‘and’ meta_input ‘ to the current user id. The other button should change ‘post_status’ to ‘pending’.

Viewing 3 posts - 1 through 3 (of 3 total)