Support

Account

Home Forums ACF PRO Can't get field value from $_POST['fields']

Solved

Can't get field value from $_POST['fields']

  • I’ve been using ACF fields to automatically populate/update the title field for a specific custom post type. The following code worked fine in ACF 4, but I’m seeing now that it’s not working after updating to ACF Pro.

    
    <?php
    add_filter( 'title_save_pre', 'title_populate' );
    function title_populate( $title ) {
    	$lnfield = $_POST['fields']['field_533c3c459931f']; // lastname
    	$fnfield = $_POST['fields']['field_533c3c349931e']; // firstname
    
      $type = get_post_type($post->ID);
    // IF I use the line below (commented), the title is populated with only the comma and space — so the title_save_pre filter is working, it is just not getting the field values
    //		if ( $type=='person' ) : 
    // If I use this line, nothing happens, because $lnfield remains empty
    		if ( $lnfield && ($type=='person') ) :
    			$title =  $lnfield . ', ' . $fnfield;
    			return $title;
    		endif;
    		return $title;
    }
    
    ?>
    

    Halp?

  • Hi @gmiddleb

    ACF PRO posts it’s data with an ‘acf’ prefix instead of ‘fields’ to avoid conflicts with 3rd party plugins etc.

    So the solution is to change $_POST['fields'] to $_POST[‘acf’].

    Annoying I agree, but much safer to use a plugin specific prefix for future proofing.

    Cheers
    E

  • Totally makes sense, and that works! Thanks for the quick reply and for your indispensable plugin.

  • For anyone having trouble with this same thing, the prefix seems to be back to “fields”, so the original code is currently working for with (ACV v 4.3.9)

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

The topic ‘Can't get field value from $_POST['fields']’ is closed to new replies.