Support

Account

Home Forums General Issues How to filter ACF post object by custom field

Unread

How to filter ACF post object by custom field

  • I have a front end ACF form – acf_form(). With a post object field. I want to limit the queried results by a custom field. The code below works, except for when i try to type in the search bar – I just get lost of errors. Any idea whats wrong with my code? Help very appreciated!

    function filter_customer_doc_query( $args, $field, $post_id ) {
      $user_id_doc = get_current_user_id();
      $business_id_doc = get_field('user_business_id', 'user_' . $user_id_doc);
      $args = array(
        'posts_per_page' => 10,
        'post_type'     => 'customer',
        'meta_key'      => 'customer_business_id',
        'meta_value'    => $business_id_doc,
      );
      return $args;
    }
    add_filter('acf/fields/post_object/query/name=doc_customer_object', 'filter_customer_doc_query', 10, 3);
Viewing 1 post (of 1 total)

The topic ‘How to filter ACF post object by custom field’ is closed to new replies.