Hi.
I have two cpts.
In the second CPT I have a Post object that is a reference of first CPT “entity”.
I have a frontend form to create new posts of the second CPT “proyect”. By default, on frontend form, this is a select2 field with all entities.
But now, I want to show only some of this entities in this select (entity).
I’m testing with the filter:
add_filter('acf/fields/post_object/query/name=entity', 'entity_object_custom_query', 10, 3);
function entity_object_custom_query ($args, $field, $post_id) {
$args = [
'meta_key' => 'year_creation',
'meta_value' => '2010'
];
return $args;
}
Then, on entity select of frontend form, is appears empty and in the debug.log file it return:
PHP Warning: Attempt to read property “post_content” on null in …
The problem, I think… I have no “post_id” becouse in the frontend form render code I have ‘post_id’ => ‘new_post’,
How can I solve this?
Regards..