我有一个前端ACF表单-acf_form()。具有发布对象字段。我想通过自定义字段限制查询结果。下面的代码有效,除了当我尝试在搜索栏中键入内容时-出现以下错误: 我得到的错误是ajax响应中的PHP错误;
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')”
还得到“未定义索引:s”和“ strpos():空针”
我的代码:
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);
答案 0 :(得分:0)
通过将上面的$ args替换为
解决了该问题$args['meta_query'] = array(
array(
'key' => 'customer_business_id',
'value' => $business_id_doc,
'compare' => '=',
)
);