简体   繁体   English

ACF关系字段搜索包括自定义字段

[英]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.

相关问题 ACF:按关系字段搜索 - ACF: search by relationship field WordPress高级自定义字段(ACF)-设置关系字段的样式-CSS - WordPress Advanced Custom Fields (ACF) - Styling the Relationship Field - CSS WordPress-在通过博客帖子进行的搜索中包括高级自定义字段(ACF),并在搜索结果中显示这些字段 - WordPress - Including an Advanced Custom Field (ACF) in a search through blog posts and displaying the fields in the search results Wordpress:PHP中的ACF自定义字段包括 - Wordpress: ACF custom field in PHP include wordpress处理与WP_Query类型相关的ACF自定义字段 - wordpress handle ACF custom fields of type relationship with WP_Query 在 Wordpress the_content() 中包含高级自定义字段 (ACF) - Include Advanced Custom Fields (ACF) in Wordpress the_content() 在自定义搜索中包含高级自定义字段 (ACF) - Wordpress - Including Advanced Custom Fields (ACF) in a Custom Search - Wordpress 按关系字段 (ACF) 为 Elementor 帖子自定义查询过滤器 - Custom Query Filter for Elementor Posts by relationship field (ACF) 在产品类别页面上显示关系acf自定义字段 - displaying a relationship acf custom field on product category page 自定义分类法中通过ACF字段的Wordpress搜索表单和搜索结果 - Wordpress search form and search result through ACF field in custom taxonomy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM