Support

Account

Home Forums ACF PRO load_field Reply To: load_field

  • I had this same problem earlier in the code when using have_rows() to retrieve the values from the related repeater field (to populate the ARTartwork_type selection set instead of get_post_meta().

    Where if I used the ID as a variable ($related_source_id) with have_rows() it would NOT work…

    if( have_rows('SRCattributes', $related_source_id) ) { 
    		
    	while( have_rows('SRCattributes', $related_source_id) ) {
    
    		the_row();
    
    		if( have_rows('SRCartwork_types') ) { 
    
    			$artwork_type_count = count(get_field('SRCattributes_SRCartwork_types', $related_source_id));
    
    			while( have_rows('SRCartwork_types') ) { 
    
    				the_row();
    
    				$inheritedvalues[] = get_sub_field( 'SRCartwork_type' );
    
    			}
    					
    		}
    
    	}
    		
    }

    but if I switched to hardcoding the $related_source_id to (14342) it worked…

    if( have_rows('SRCattributes', 14342) ) { 
    		
    	while( have_rows('SRCattributes', 14342) ) {
    
    		the_row();
    
    		if( have_rows('SRCartwork_types') ) { 
    
    			$artwork_type_count = count(get_field('SRCattributes_SRCartwork_types', $related_source_id));
    
    			while( have_rows('SRCartwork_types') ) { 
    
    				the_row();
    
    				$inheritedvalues[] = get_sub_field( 'SRCartwork_type' );
    
    			}
    					
    		}
    
    	}
    		
    }

    However when I switched to using get_post_meta() it worked with a variable for the $related_source_id…

    $count = intval( get_post_meta( $related_source_id, 'SRCattributes_SRCartwork_types', true ) );
    	
    	// Loop through the repeater fields and put their values into the array.
    	for ( $i=0; $i<$count; $i++ ) {
    		
    	$selection = get_post_meta( $related_source_id, 'SRCattributes_SRCartwork_types'.'_'.$i.'_'.'SRCartwork_type' );
    		
    	$inheritedvalues[$i] = $selection[0];
    		
    	}

    So I got this portion of the code to work when I used get_post_meta() method (something about an infinite loop.)

    I am hoping there is a similar fix for getting the $post_id of the active Admin screen to work where I can use a variable for post ID of the current admin screen rather then having to hardcode it, which does not work since it needs to be dynamic.

    I really hope this all makes sense! thank you so much if you can help (Its driving me crazy).