简体   繁体   English

ACF:中继器字段返回不稳定的API数据,而新字段在保存时将不接受新数据

[英]ACF: repeater fields returning erratic API data and new fields won't accept new data on save

The site we are working on has broken in the last week and we have no idea what is going on. 我们正在处理的网站在上周已损坏,我们不知道发生了什么。 Here is a list of issues, and the steps we've taken to troubleshoot them: 以下是问题列表,以及为解决这些问题而采取的步骤:

  • In our API call we are using get_field() and get_fields() to request data from a repeater, but from time to time this returns null, false, or the length of the array. 在我们的API调用中,我们使用get_field()和get_fields()向中继器请求数据,但有时会返回null,false或数组长度。 All the content is still in the database. 所有内容仍在数据库中。
  • When trying to create new repeater content the child fields of the parent repeater field will not save on first save, but once re-added can be saved afterwards. 尝试创建新的转发器内容时,父转发器字段的子字段不会在第一次保存时保存,但是一旦重新添加,就可以在以后保存。
  • When creating new fields (any field, not just a repeater) the key will change from the field_xxxxxxxxxxxxxx format to be the same as the name ie short-description. 当创建新字段(任何字段,而不仅仅是转发器)时,密钥将从field_xxxxxxxxxxxxxx格式更改为与名称相同,即简短描述。
  • Old repeater fields can be updated or saved to, whereas new ones won't save data. 可以将旧的转发器字段更新或保存到其中,而新的转发器字段将不保存数据。

Troubleshooting Steps 故障排除步骤

Thanks in advance for any guidance you're able to provide :) 在此先感谢您能够提供的任何指导:)

Turns out it was this piece of code in functions.php that we were using to re-write the slugs on save of the posts was the issue: 原来是问题所在的是functions.php中的这段代码,我们用来重写这些代码是问题所在:

function myplugin_update_slug( $data, $postarr ) {
    if ( ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
        $data['post_name'] = sanitize_title( $data['post_title'] );
    }
    return $data;
}

The sanitize_title() function was overwriting the key field and causing ACF to lose track of the fields. sanitize_title()函数覆盖了关键字段,并导致ACF失去了对该字段的跟踪。

We resolved this by activating a clean WP theme, then once we confirmed that it was some code in our child theme we just commented out code in our functions.php file until the offending function was found. 我们通过激活一个干净的WP主题解决了这一问题,然后,当我们确认它是子主题中的某些代码时,我们只是在我们的functions.php文件中注释掉了代码,直到发现有问题的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM