我有一个功能,当需要满足客户需求时,我可以在许多自定义主题中重复使用。我知道现在可以通过ACF Pro中的中继器实现这一点,但由于我有一个工作功能,所以我选择使用它。
我现在面临的问题是,我真的很难在v5.4.2中的自定义帖子类型上显示这一点。我甚至安装了“classic Editor”插件,看看这是否是遗留元字段的问题,但没有乐趣。。。
带注释的函数代码为:
//custom post type attachments for bikes.
add_filter( \'attachments_default_instance\', \'__return_false\' ); // disable the default instance
function post_attachments( $attachments )
{
$fields = array(
array(
\'name\' => \'title\', // unique field name
\'type\' => \'text\', // registered field type
\'label\' => __( \'Title\', \'attachments\' ), // label to display
\'default\' => \'title\', // default value upon selection
),
array(
\'name\' => \'caption\', // unique field name
\'type\' => \'textarea\', // registered field type
\'label\' => __( \'Caption\', \'attachments\' ), // label to display
\'default\' => \'caption\', // default value upon selection
),
);
$args = array(
// title of the meta box (string)
\'label\' => \'Bike Images\',
// all post types to utilize (string|array)
\'post_type\' => array( \'post\', \'page\', \'used\' ),
// meta box position (string) (normal, side or advanced)
\'position\' => \'normal\',
// meta box priority (string) (high, default, low, core)
\'priority\' => \'high\',
// allowed file type(s) (array) (image|video|text|audio|application)
\'filetype\' => null, // no filetype limit
// include a note within the meta box (string)
\'note\' => \'Attach files here!\',
// by default new Attachments will be appended to the list
// but you can have then prepend if you set this to false
\'append\' => true,
// text for \'Attach\' button in meta box (string)
\'button_text\' => __( \'Attach Files\', \'attachments\' ),
// text for modal \'Attach\' button (string)
\'modal_text\' => __( \'Attach\', \'attachments\' ),
// which tab should be the default in the modal (string) (browse|upload)
\'router\' => \'browse\',
// whether Attachments should set \'Uploaded to\' (if not already set)
\'post_parent\' => false,
// fields array
\'fields\' => $fields,
);
$attachments->register( \'post_attachments\', $args );
}
add_action( \'attachments_register\', \'post_attachments\' );
我一直坚持这样做,所以任何提示都将不胜感激。我还需要通过v2 API提供这些图像文件的URL。这一要求是否使使用诸如ACF Pro之类的plgin更加相关?
我担心在构建不打算转售的定制主题时使用过多的第三方插件。