How add a custom field in a custom post type

I want to add a custom field in my custom post type. I want to add a text field in the custom post type but I dont know how to do that. Here is my code that I have implemented in functions.php in my themes.

add_action( 'init', 'register_cpt_advert' );

function register_cpt_advert() {

$labels = array( 
    'name' => _x( 'Adverts', 'advert' ),
    'singular_name' => _x( 'Advert', 'advert' ),
    'add_new' => _x( 'Add New', 'advert' ),
    'add_new_item' => _x( 'Add New Advert', 'advert' ),
    'edit_item' => _x( 'Edit Advert', 'advert' ),
    'new_item' => _x( 'New Advert', 'advert' ),
    'view_item' => _x( 'View Advert', 'advert' ),
    'search_items' => _x( 'Search Adverts', 'advert' ),
    'not_found' => _x( 'No advert found', 'advert' ),
    'not_found_in_trash' => _x( 'No adverts found in Trash', 'advert' ),
    'parent_item_colon' => _x( 'Parent Advert:', 'advert' ),
    'menu_name' => _x( 'Adverts', 'advert' ),
);

$args = array( 
    'labels' => $labels,
    'hierarchical' => false,
    'description' => 'Show image adverts on videos',
    'supports' => array( 'title', 'thumbnail'),
    //'taxonomies' => array( 'category', 'post_tag', 'page-category' ),
    'public' => false,
    'show_ui' => true,
    'show_in_menu' => true,


    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => true,
    'has_archive' => false,
    'query_var' => false,
    'can_export' => true,
    'rewrite' => false,
    'capability_type' => 'post'
);
register_post_type( 'advert', $args );
}

Related posts

Leave a Reply

3 comments