Support

Account

Home Forums General Issues acf/fields/post_object/query/ in frontend form – $post_id null

Solved

acf/fields/post_object/query/ in frontend form – $post_id null

  • 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..

  • what is the rest of the error?

    PHP Warning: Attempt to read property “post_content” on null in …

    is the error in on of the ACF files?

    Or somewhere else?

  • Hi!

    Sorry but I found the problem and is for another cause.

    Was for an wp_ajax function.

    All resolved.

    Thanks, sorry and regards…

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.