[英]ACF relationship field search include custom fields
I am using the code below to modify the acf/fields/relationship/result in order to include extra field data to the list. 我正在使用下面的代码修改acf / fields / relationship / result,以便将额外的字段数据包括到列表中。 However, this data is not searchable if I use the relationship field's search feature. 但是,如果使用关系字段的搜索功能,则无法搜索此数据。 Can anyone come up with a way I can extend the search function to include this data? 谁能提出一种我可以扩展搜索功能以包括此数据的方法? I understand I have to use acf/fields/relationship/query to do this, but I do not know how. 我了解我必须使用acf / fields / relationship / query来执行此操作,但是我不知道如何操作。
Here is the code that adds the relevant data to the list: 这是将相关数据添加到列表中的代码:
function id_relationship_result( $title, $post, $field, $post_id ) {
// load a custom field from this $object and show it in the $result
$city = get_field('city', $post->ID);
$state = get_field('state', $post->ID);
// append to title
$title_new = $state . ', ' . $city . ' ' . $title;
// return
return $title_new;
}
Any help is appreciated.... 任何帮助表示赞赏。
You're not too far off here - you just need to use a different ACF hook. 您在这里不太远-您只需要使用其他ACF挂钩即可。 To modify the title on return, you have to use the ACF acf/fields/relationship/result hook - which is explained here - http://www.advancedcustomfields.com/resources/acf-fields-relationship-result/ 要修改退货标题,您必须使用ACF acf / fields / relationship / result钩子-在此处进行说明-http: //www.advancedcustomfields.com/resources/acf-fields-relationship-result/
So, in your case here, you could add the following to your functions.php file 因此,在这里,您可以将以下内容添加到您的functions.php文件中
add_filter('acf/fields/relationship/result/name=your_relationship_field_name', 'id_relationship_result', 10, 4);
function id_relationship_result($title, $post, $field, $post_id){
// load a custom field from this $object and show it in the $result
$city = get_field('city', $post->ID);
$state = get_field('state', $post->ID);
// append to title
$title = $state . ', ' . $city . ' ' . $title;
// return
return $title;
}
That will hopefully allow your title to list the data you need and allow for easier filtering 希望这将使您的标题列出所需的数据,并简化过滤
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.