Actually lowercase post_id
is the correct usage. Thanks!
Right now I have solved this by not using a post_object field type. Instead I’m using select field type and manually populating its choices via acf/load_field
filter.
Initially I thought post_object field could handle everything automatically.
Yes, everything is registered in functions.php
1. add_action( 'init', 'registerPostTypes', 0 );
2. add_action( 'acf/init', 'addFieldsByLevel' );
3. In addFieldsByLevel
function I’m looping through taxonomy terms and adding a field for each of the term (code in the earlier post).
And yes just before the loop I’m checking for the post ID which works on admin
if ( isset( $_GET['post'] ) ) {
$post_id = $_GET['post'];
} else if ( isset( $_POST['post_ID'] ) ) {
$post_id = $_POST['post_ID'];
} else {
return;
}
The fields are registered using acf/init
action (with default priority 10) and the code is placed after CPT registration.
Is there a way to debug select2 ajax requests?
Aaand 10 months later I stumbled on this bug again.
I’m registering fields dynamically:
foreach( $levels as $i => $level ) {
$name = "level_{$level->term_id}_winner";
acf_add_local_field([
'parent' => 'group_5cb57c19cffde',
'key' => "field_{$name}",
'label' => sprintf( __( '%s level winner', 'imatch' ), $level->name ),
'name' => $name,
'type' => 'post_object',
'post_type' => [ 'im_registration' ],
'taxonomy' => [],
'allow_null' => true,
'return_format' => 'id',
]);
}
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.