Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter ds7ilg7

    (@ds7ilg7)

    Yes, this does help – thank you. I’ll be able to take a look at it tomorrow and I’ll report back then.

    I appreciate your work and for the support you extend.

    Have a nice evening.

    Thread Starter ds7ilg7

    (@ds7ilg7)

    I apologize in advance – I thought I had the code in a module.

    Thread Starter ds7ilg7

    (@ds7ilg7)

    You are impressively quick with support!

    I’m sure you’re right about ‘the system is trying to retrieve a term that doesn’t exists during the assignation’. I believe your assumption is correct because the fields are in a repeater. The loop happens after the post is created. I perform 2 things in the child posts:

    1. Create a new post from each row of the repeater, then,
    2. Take the fields out of the repeater and into regular fields in the back end.

    I do this because the site relies extensively on the field values. Querying repeaters can be quite taxing.

    The code:

    // Create Multiple Truck Order posts from repeater, then move fields out of the repeater for easier queries
    // The first loop creates the post. Then each post is updated with it's OWN values - meaning there is no repeater in the new post id.
    function post_truck_details($post_id ){
    
    	// get the repeater
    	$values = get_field('truck_order_info', $post_id);
    	// loop through the repeater
    	foreach( $values as $value ) { 
    		
    	// set args
    	$new_post = array(
    		'post_title' =>  $value['truck_quantity'].' '.$value['eq_truck_type'].' '.$value['trailer_type'].' @ '.$value['truck_start_time'],	
    		'post_type' => 'truck_order',
    		'post_parent' => $post_id,		
    		'post_status'	=> 'draft',
       );      
    
    	// Post Truck Order
    		$new_post_id = wp_insert_post($new_post);		
    			wp_set_object_terms($new_post_id, get_term(482)->slug, 'truck-order-status', true);
    			wp_set_object_terms( $new_post_id, $eqtrucktype = $value ['eq_truck_type'], 'eq_cat', true );
    			wp_set_object_terms( $new_post_id, $trailertype = $value['trailer_type'], 'eq_cat', true );
    			wp_set_object_terms( $new_post_id, $hazmatend = $value['requires_hazmat_drivers'], 'cdl_endorsement', true );	
    
    	//Get and update fields outside of repeater 
    		$projname = get_field('project_name', $post_id);
    		$projcon = get_field ('project_contractor', $post_id );
    		$projpm = get_field('project_pm', $post_id);
    		$workdate = get_field('work_date', $post_id);
    
    			update_field( 'project_name', $projname, $new_post_id);
    			update_field( 'project_contractor', $projcon, $new_post_id );
    			update_field( 'project_pm', $projpm, $new_post_id );
    			update_field( 'work_date', $workdate, $new_post_id );
    		
    	// Move repeater field values to each post's regular field
    	if (have_rows('truck_order_info', $post_id)) {
    	while(have_rows('truck_order_info', $post_id)) {
    	the_row();
    		$eqtrucktypes = array();
    			foreach( $eqtrucktypes as $eqtrucktype );
    				$eqtrucktype = $value['eq_truck_type'];
    		$tractorselects = array();
    			foreach( $tractorselects as $tractorselect );
    				$tractorselect = $value['tractor_selection'];	
    		$trailertypes = array();
    			foreach( $trailertypes as $trailertype );
    				$trailertype = $value['trailer_type'];
    		$truckstarts = array();
    			foreach( $truckstarts as $truckstart );		
    				$truckstart = $value['truck_start_time'];
    		$quans = array();
    			foreach( $quans as $quan );
    				$quan = $value['truck_quantity'];
    		$loadloctypes = array();
    			foreach( $loadloctypes as $loadloctype );		
    				$loadloctype = $value['load_location_type'];
    		$loadlocsups = array();
    			foreach( $loadlocsups as $loadlocsup );		
    				$loadlocsup = $value['load_location_supplier'];	
    		$loadlocsrecyclers = array();
    			foreach( $loadlocsrecyclers as $loadlocsrecycler );		
    				$loadlocsrecycler = $value['load_location_recycler'];
    		$loadlocotherprojs = array();
    			foreach( $loadlocotherprojs as $loadlocotherproj );		
    				$loadlocotherproj = $value['load_location_other_project'];	
    		$loadlocsrecyclers = array();
    			foreach( $loadlocsrecyclers as $loadlocsrecycler );		
    				$loadlocsrecycler = $value['load_location_recycler'];
    		$loadlocothersups = array();
    			foreach( $loadlocothersups as $loadlocothersup );		
    				$loadlocothersup = $value['load_location_other_supplier'];
    		$altloadlocs = array();
    			foreach( $altloadlocs as $altloadloc );		
    				$altloadloc = $value['alternate_load_location'];
    		$descriptions = array();
    			foreach( $descriptions as $description );
    				$description = $value['load_description'];
    		$weights = array();
    			foreach( $weights as $weight );
    				$weight = $value['load_weight'];
    		$lengths = array();
    			foreach( $lengths as $length );
    				$length = $value['load_length'];			
    		$loadagtypes = array();
    			foreach( $loadagtypes as $loadagtype );		
    				$loadagtype = $value['load_side_aggregate_type'];	
    		$loadrecycleagtypes = array();
    			foreach( $loadrecycleagtypes as $loadrecycleagtype );		
    				$loadrecycleagtype = $value['load_side_rec_aggregate_type'];			
    		$mattypes = array();
    			foreach( $mattypes as $mattype );		
    				$mattype = $value['material_type'];	
    		$workonsites = array();
    			foreach( $workonsites as $workonsite );		
    				$workonsite = $value['work_onsite'];
    		$droploctypes = array();
    			foreach( $droploctypes as $droploctype );		
    				$droploctype = $value['drop_location_type'];
    		$droplocsups = array();
    			foreach( $droplocsups as $droplocsup );		
    				$droplocsup = $value['drop_location_supplier'];	
    		$droplocrecycles = array();
    			foreach( $droplocrecycles as $droplocrecycle );		
    				$droplocrecycle = $value['drop_location_recycler'];	
    		$droploclandfills = array();
    			foreach( $droploclandfills as $droploclandfill );		
    				$droploclandfill = $value['drop_location_landfill'];	
    		$droplocotherprojs = array();
    			foreach( $droplocotherprojs as $droplocotherproj );		
    				$droplocotherproj = $value['drop_location_other_project'];	
    		$droplocs = array();
    			foreach( $droplocs as $droploc );		
    				$droploc = $value['drop_location'];
    		$droplocothersups = array();
    			foreach( $droplocothersups as $droplocothersup );		
    				$droplocothersup = $value['drop_location_other_supplier'];
    		$confirmagpups = array();
    			foreach( $confirmagpups as $confirmagpup );		
    				$confirmagpup = $value['confirm_agg_pickup'];
    		$dropsideagtypes = array();
    			foreach( $dropsideagtypes as $dropsideagtype );		
    				$dropsideagtype = $value['drop_side_aggregate_type'];
    		$confirmrecycleagpups = array();
    			foreach( $confirmrecycleagpups as $confirmrecycleagpup );		
    				$confirmrecycleagpup = $value['confirm_rec_agg_pickup'];
    		$dropsiderecycleagtypes = array();
    			foreach( $dropsiderecycleagtypes as $dropsiderecycleagtype );		
    				$dropsiderecycleagtype = $value['drop_side_rec_aggregate_type'];
    		$contaminateds = array();
    			foreach( $contaminateds as $contaminated );		
    				$contaminated = $value['is_material_contaminated'];	
    		$hazmatends = array();
    			foreach( $hazmatends as $hazmatend );		
    				$hazmatend = $value['requires_hazmat_drivers'];			
    		$backhauls = array();
    			foreach( $backhauls as $backhaul );		
    				$backhaul = $value['back_haul_other'];
    		$bhothmats = array();
    			foreach( $bhothmats as $bhothmat );		
    				$bhothmat = $value['back_haul_other_material'];
    		$bhdescriptions = array();
    			foreach( $bhdescriptions as $bhdescription );		
    				$bhdescription = $value['backhaul_description'];	
    		$bhweights = array();
    			foreach( $bhweights as $bhweight );		
    				$bhweight = $value['backhaul_weight'];	
    		$bhlengths = array();
    			foreach( $bhlengths as $bhlength );		
    				$bhlength = $value['backhaul_length'];				
    		$addinsts = array();
    			foreach( $addinsts as $addinst );		
    				$addinst = $value['additional_instructions'];	
    		
    update_field( 'eq_truck_type', $eqtrucktype, $new_post_id );
    update_field( 'tractor_selection', $tractorselect, $new_post_id );		
    update_field( 'trailer_type', $trailertype,  $new_post_id );
    update_field( 'truck_start_time', $truckstart,  $new_post_id );	
    update_field( 'truck_quantity', $quan,  $new_post_id );		
    update_field( 'load_location_type', $loadloctype,  $new_post_id );
    update_field( 'load_location_supplier', $loadlocsup,  $new_post_id );
    update_field( 'load_location_recycler', $loadlocsrecycler,  $new_post_id );
    update_field( 'load_location_other_project', $loadlocotherproj,  $new_post_id );	
    update_field( 'load_location_other_supplier', $loadlocothersup,  $new_post_id );
    update_field( 'alternate_load_location', $altloadloc,  $new_post_id );
    update_field( 'load_description', $description,  $new_post_id );
    update_field( 'load_weight', $weight,  $new_post_id );
    update_field( 'load_length', $length,  $new_post_id );	
    update_field( 'load_side_aggregate_type', $loadagtype,  $new_post_id );		
    update_field( 'load_side_rec_aggregate_type', $loadrecycleagtype,  $new_post_id );
    update_field( 'material_type', $mattype,  $new_post_id );
    update_field( 'work_onsite', $workonsite,  $new_post_id );	
    update_field( 'drop_location_type', $droploctype,  $new_post_id );
    update_field( 'drop_location_supplier', $droplocsup,  $new_post_id );
    update_field( 'drop_location_recycler', $droplocrecycle,  $new_post_id );
    update_field( 'drop_location_landfill', $droploclandfill,  $new_post_id );
    update_field( 'drop_location_other_project', $droplocotherproj,  $new_post_id );
    update_field( 'drop_location', $droploc,  $new_post_id );
    update_field( 'drop_location_other_supplier', $droplocothersup,  $new_post_id );
    update_field( 'confirm_agg_pickup', $confirmagpup,  $new_post_id );
    update_field( 'drop_side_aggregate_type', $dropsideagtype,  $new_post_id );
    update_field( 'confirm_rec_agg_pickup', $confirmrecycleagpup,  $new_post_id );
    update_field( 'drop_side_rec_aggregate_type', $dropsiderecycleagtype,  $new_post_id );
    update_field( 'is_material_contaminated', $contaminated,  $new_post_id );
    update_field( 'requires_hazmat_drivers', $hazmatend,  $new_post_id );
    update_field( 'back_haul_other', $backhaul,  $new_post_id );
    update_field( 'back_haul_other_material', $bhothmat,  $new_post_id );
    update_field( 'backhaul_description', $bhdescription,  $new_post_id );
    update_field( 'backhaul_weight', $bhweight,  $new_post_id );
    update_field( 'backhaul_length', $bhlength,  $new_post_id );	
    update_field( 'additional_instructions', $addinst,  $new_post_id );	
    update_field( 'order_to_pm', $post_id,  $new_post_id );		
    			}			
    		}
    	}
    }
    add_filter('acfe/form/submit/post/form=new-truck-order', 'post_truck_details', 10, 5);
    
    Thread Starter ds7ilg7

    (@ds7ilg7)

    THANK YOU SO MUCH KONRAD!

    I worked and re-worked my method(s) for 2 days with no success. It took me about 3 minutes to accomplish what I needed by following your solution.

    Since working with ACFE, I’ve been able to figure many things out by stalking your support forum for solutions to other problems. It’s obvious that you spend a lot of time understanding your user’s questions and you are extremely helpful with your detailed replies.

    Again, thank you.

    Thread Starter ds7ilg7

    (@ds7ilg7)

    Thanks Konrad,

    In case anyone has a similar situation, this worked for me:

    // Post New Parent Post  and Create Multiple Child posts from repeater
    function post_project_managers($post_id){
        // get the repeater
        $values = get_field('use_your_repeater_name_here', $post_id);
           
        // loop through the repeater
        foreach( $values as $value ) {
    		
       // set the child post arguments
            $new_post = array(
        			'post_title' => $value[‘name_your_post’], //use any field to name your psot
    			'post_type' => 'post', // set to post or use any CPT
    			'post_parent' => $post_id, //the parent comes from the 1st action of the form		
    			'post_status'	=> 'draft',
    		       );        
    		// post pm
    		$new_post_id = wp_insert_post($new_post);
    
    // Save related repeater field values to the corresponding new post
    $field_key = "field_1234567"; //insert repeater key 
    $value = array(
        array(
            "field_1234568"   => $value['field_name'],
            "field_1234569"   => $value['field_name'],
            "field_1234560"   => $value['field_name'],
            "field_1234570"   => $value['field_name']
    	)
    );
    update_field( $field_key, $value, $new_post_id );
    	}
    }
    add_filter('acf/save_post', 'my_acf_post_field', 20);
    add_filter('acfe/form/submit/post/form=test-post-form', 'post_project_managers', 10, 5);
    Thread Starter ds7ilg7

    (@ds7ilg7)

    I just tried again. The behavior was different than the last time, but after it appeared that the transaction was complete, Paypal redirected me to this message:

    “Sorry about that

    Looks like this action is not supported. Please return and report this error so that we can support it in the future. (invalid client_id or redirect_uri) ”

    I’ll take a look at Pro and likely support you and ACF Ex in that way.

    Thank you for your excellent work.

    Thread Starter ds7ilg7

    (@ds7ilg7)

    Dear Conrad,

    Thank you for your prompt reply. Please feel free to mark this topic as closed.

    Is it possible to contact you directly for custom work?

    Thread Starter ds7ilg7

    (@ds7ilg7)

    Dear Konrad,

    Your solution works perfectly, thank you. However, I have run into a different problem.

    Originally, I created 1 form with 2 field groups:
    1. Field group 1 is general company info
    2. Field group 2 is employees of the company. (For testing purposes, I created three field groups containing first name, last name, phone number.)

    Within the form actions, I created:
    1. a parent CPT (“Contractor”) containing the 1st field group (general company info)
    2. multiple child CPTs (employees of the Contractor) containing the 2nd field group.

    Your solution works perfectly as long as I fill out all 3 employees. If I only fill in one employee, my form actions will still create 3 new child CPT’s, but 2 of them are created as “No title” and blank CPT children are created. This is expected since my form actions are set up and mapped to create 3 posts.

    Do you have any suggestions on how I can allow the Contractor to fill out any number of employees (could be anywhere between 1-20) and so that my form actions do not create blank posts of unused field groups?

    Thanks so much for your help.

Viewing 8 replies - 1 through 8 (of 8 total)