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)