简体   繁体   English

WordPress ACF:在管理部分中为自定义帖子类型添加默认行到Repeater字段类型

[英]WordPress ACF: add default rows to Repeater field type in admin section for a custom post type

The Advanced Custom Fields plugin for WordPress provides a Repeater type field. WordPress的高级自定义字段插件提供了一个Repeater类型字段。 I already know how to add rows to this via the code but what I don't know is how to get the wp-admin console for the custom post to include this code so that the dynamically added rows are shown in the editor. 我已经知道如何通过代码向此添加行,但我不知道如何让自定义帖子的wp-admin控制台包含此代码,以便在编辑器中显示动态添加的行。

So that's the question: where do I put my custom add_rows() function if I want those rows to be visible to the editor? 所以这就是问题:如果我希望编辑器看到这些行,我在哪里放置自定义add_rows()函数?

Currently I have the add_rows() code in the single page template for that custom post type.. which of course doesn't render to the editor. 目前,我在该自定义帖子类型的单页模板中有add_rows()代码..当然这不会呈现给编辑器。

The answer to this is twofold: 答案是双重的:

  1. Firstly there's no need to add_rows() (which modifies the DB) for the admin section . 首先,管理员部分不需要add_rows() (修改数据库)。 I just used a filter instead which modifies the values directly, as described in this article here: https://support.advancedcustomfields.com/forums/topic/dynamically-generate-subfield-content/ 我只使用了一个过滤器,它直接修改了值,如本文所述: https//support.advancedcustomfields.com/forums/topic/dynamically-generate-subfield-content/
  2. To make it run in the admin console, the code should be in functions.php rather than in the custom post type template. 要使其在管理控制台中运行,代码应该在functions.php中,而不是在自定义帖子类型模板中。

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

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