【问题标题】:How to create customs fields in a CPT without any plugin?如何在没有任何插件的情况下在 CPT 中创建自定义字段?
【发布时间】:2022-01-25 21:34:12
【问题描述】:

我对这个问题的目标是什么

我目前正在为 WordPress 网站构建自定义插件。当我的插件被激活时,它正在创建一个新的自定义帖子类型,它目前具有默认输入字段。

我希望这个新的自定义帖子类型拥有比默认的全新的输入字段不使用任何外部插件

我发现了什么

我在网上搜索了很多关于“在 CPT 中创建海关字段?”,但我发现的只是使用 ACF 等插件的一些答案。我也去了 WordPress 的官方文档,但我只找到了如何创建一个新的 Custom Post Type

我的代码

function __construct()
{
    $this->plugin_name = plugin_basename(__FILE__);
    add_action('init', array($this, 'custom_post_type'));
    
}

function custom_post_type(){
    register_post_type('logos', ['public' => true, 'label' => 'Logo Upload']);
}

【问题讨论】:

  • 谢谢!我去看看!

标签: php wordpress advanced-custom-fields custom-post-type custom-fields


【解决方案1】:

您正在寻找的是自定义元框(包含字段)。

这当然是可能的,您可以在此处找到有关它的文档:https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    相关资源
    最近更新 更多