1
votes

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 - a get the following errors: The errors I am getting are PHP errors in ajax response;

0: "PhpConsole\Handler->handleError()"

1: "strpos()"

2: "acf_order_by_search()"

3: "acf_field_post_object->get_ajax_query()"

4: "acf_field_post_object->ajax_query()"

5: "do_action('wp_ajax_acf/fields/post_object/query')"

Also getting "Undefined index: s" and "strpos(): Empty needle"

My code:

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);
2

2 Answers

1
votes

Solved it by replacing $args above with:

$args['meta_query'] = array(
    array(
        'key'       => 'customer_business_id',
        'value' => $business_id_doc,
        'compare' => '=',
    )
);
0
votes

i need do something similar but i can't find the correct way.

I have 2 fields:

  1. type taxonomy called "category"
  2. type post object called "products"

What i want? populate the dropdown of "products" only with the "category" selected.

I'm trying this:

function filter_product_query( $args, $categorId ) {    
    
    $categorId = get_field('category_v1');
    
    $args = array(
        'post_type' => 'product',
        'posts_per_page' => 3,
        'tax_query'      => array( array(
            'taxonomy'   => 'product_cat',
            'field'      => 'term_id',
            'terms'      => $categorId ,
        ) )
    );          
    return $args;
    
}
add_filter('acf/fields/post_object/query/key=field_61e745e87a5a6', 'filter_product_query', 10, 4);

But doesn't work.

Taxonomy field configuration

Post object field configuration