Search code examples
phpwordpressadvanced-custom-fieldscustom-post-typecustom-fields

How to create customs fields in a CPT without any plugin?


What's my goal with this question

I'm currently building a custom plugin for a WordPress website. When my plugin is activating, it's creating a new Custom Post Type that has default input fields for the moment.

I want this new Custom Post Type to have completely new input fields than the default one without using any external plugin.

What I've found

I searched a lot on the web on "Creating customs fields in a CPT?", but all I've found is some answers using plugins like ACF. I also went on the official documentation of WordPress, but I only found how to create a new Custom Post Type.

My code

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']);
}


Solution

  • What you're looking for, are custom meta-boxes (which contain fields).

    Thats certainly possible and you can find documentation about it here: https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/