Support

Account

Home Forums Backend Issues (wp-admin) Update both parent and child posts

Unread

Update both parent and child posts

  • Hi,
    I’m tryng to update both parent and child post title while saving the parent post.
    The parent post is updated, but the child post is not updated. What am I doing wrong?
    Thanks in advance…

     function post_title_attestato_fune_updater( $post_id ) {
    
        $fune_post = array();
        $fune_post['ID'] = $post_id;
    	
        
    	$companies = get_field('spettle');
    	foreach($companies as $company){
        $company_name = $company->post_title;
        $company_id = $company->ID;
        $company_name;
          }
    	  
    	$matricole_post = array();
        $matricole_post['ID'] = $post_id; 
    	  
    	$matricole = get_field('matricola');
    	foreach($matricole as $post){
        $matricola_name = $post->numero_di_fabbrica;
    	$matricola_macchinario = $post->tipo_di_macchinario;
        $matricola_id = $post->ID;
        $matricola_name;
    	$matricola_macchinario;
          } 
    
        if ( get_post_type() == 'fune' ) {
    		$pipe = ' - ';
    		
    	  $fune_post['post_title'] = $company_name . ' ' .$pipe . '  ' . $matricola_macchinario . '  ' .$pipe . '  ' . $matricola_name;
        } 
    
        // Update the post into the database
        wp_update_post( $fune_post );
    	
    //until here everything goes well, but I can't update the child post below	
      
         if ( get_post_type() == 'annotazioni' ) {
    		$pipe = ' - ';	
    		
    	  $annotazioni_post['post_title'] = $company_name . ' ' .$pipe . '  ' . $matricola_macchinario . '  ' .$pipe . '  ' . $matricola_name;
        } 
    	   wp_update_post( $annotazioni_post );	
      }
Viewing 1 post (of 1 total)

The topic ‘Update both parent and child posts’ is closed to new replies.