
I’m using ACF Pro v5.4.2 (I’ve also tested with v5.4.5). I’m having an a problem with the post object select field appearing as empty after saving the post in the admin. It only happens with post objects with a custom post status (posts with the post status of “published” show up fine).
Here is the code I’m using to modify the posts returned to limit the posts:
// Edit output of Q&A post object in ACF admin to show only published/answered posts
function fan_question_post_object_query( $args, $field, $post_id ) {
$args['post_status'] = array('publish','answered');
return $args;
}
add_filter('acf/fields/post_object/query/name=fan_question', 'fan_question_post_object_query', 10, 3);
// Shorten post title shown on Q&A post object select field
function fan_question_post_object_result( $title, $post, $field, $post_id ) {
$title = wp_trim_words($title, 15, "...");
return $title;
}
add_filter('acf/fields/post_object/result/name=fan_question', 'fan_question_post_object_result', 10, 4);
I’ve checked my logs for errors and there are none. I’ve done done some debugging and narrowed it down to some bug in the rendering of the field. Comparing a var dump of the $fields returned on the page I can see that the $fields[choices] array is returning as empty.
I’ve found the source of the issue. The custom post status must be set with ‘exclude_from_search’ argument set to false in order to appear in the selects.