Thanks for the help James, ‘exclude’ has resolved my issue.
Hi James,
Thanks for the quick response. However, I have created a brand new installation of Twentyseventeen and tested with the default post and page with no other plugins installed and I get the same issue.
In this situation, I have added a Field Group to POSTS with a single Post Object field:
In my functions file, I have the following filter to exclude the Sample Page with an ID of 2:
But when I select the Field on a post, you can see that the Sample Page is still available for selection:
What am I doing wrong?
Appreciate your help and have a great Christmas ;o)
Hi Elliot, I have the answer:
function my_function( $value ) {
if ( empty( $value ) ) :
$value = $_POST['fields']['field_5252ea93ea1f6'] . $_POST['fields']['field_5252aeaf0a86b'];
return $value;
endif;
return $value;
}
add_filter('title_save_pre', 'my_function');
Sorry for the Newbie questions and thanks for your help.
Regards, Ian.
Hi Elliot thanks for the heads-up and first-class support.
For those that are interested, I resolved my issue with the following code:
function MY_FUNCTION_NAME( $value ) {
if ( !$value ) : // IF VALUE EMPTY, RETURN NEW VALUE
$value = get_field( 'MY_CUSTOM_FIELD_NAME', $POST_ID) );
return $value;
endif;
return $value; // RETURN EXISTING VALUE
};
add_filter( 'acf/load_value/name=MY_CUSTOM_FIELD_NAME', 'MY_FUNCTION_NAME' );
Thanks Elliot, that make a lot of sense… I’m new to backend development so I was wondering if you could point me in the right direction for using the $_POST array and field key?
I’ve tried the following code without success:
function my_function( $value ) {
if ( empty( $value ) ) :
return $_POST['field_5252ea93ea1f6'] . $_POST['field_5252aeaf0a86b'];
endif;
return $value;
}
add_filter('title_save_pre', 'my_function');
Am I going off in the completely wrong direction?
Thanks, Ian.
OK, so this works on UPDATE but not on PUBLISH when the initial post is created:
function my_function( $value ) {
if ( empty( $value ) ) :
return get_field( "firstname" ) . get_field( "lastname" );
endif;
return $value;
}
add_filter('title_save_pre', 'my_function');
Any ideas anyone?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.