I am new to WordPress and hence learning to make custom plugins. For this purpose, I have taken a fresh Bluehost account to practice things on it. As this account is fresh, no other plugin is installed over it.
Following this tutorial, I make a custom plugin. That plugin appeared in the plugins tab. But when I activate it, the Custom post type does not appear in WP-admin left nav-bar. I then followed another tutorial, but the same thing happened. My DEBUG is on, but no error gets thrown. I have tried all solutions given on google but no result.
Plugin file:
function tutsplus_register_post_type() {
// movies
$labels = array(
'name' => __( 'Movies' , 'tutsplus' ),
'singular_name' => __( 'Movie' , 'tutsplus' ),
'add_new' => __( 'New Movie' , 'tutsplus' ),
'add_new_item' => __( 'Add New Movie' , 'tutsplus' ),
'edit_item' => __( 'Edit Movie' , 'tutsplus' ),
'new_item' => __( 'New Movie' , 'tutsplus' ),
'view_item' => __( 'View Movie' , 'tutsplus' ),
'search_items' => __( 'Search Movies' , 'tutsplus' ),
'not_found' => __( 'No Movies Found' , 'tutsplus' ),
'not_found_in_trash' => __( 'No Movies found in Trash' , 'tutsplus' ),
);
$args = array(
'labels' => $labels,
'has_archive' => true,
'public' => true,
'hierarchical' => false,
'supports' => array(
'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes'
),
'rewrite' => array( 'slug' => 'movies' ),
'show_in_rest' => true
);
}
add_action( 'init', 'tutsplus_register_post_type' );
Can anyone help me in this regard?
>Solution :
You forget to register_post_type. try the below code.
function tutsplus_register_post_type() {
// movies
$labels = array(
'name' => __( 'Movies' , 'tutsplus' ),
'singular_name' => __( 'Movie' , 'tutsplus' ),
'add_new' => __( 'New Movie' , 'tutsplus' ),
'add_new_item' => __( 'Add New Movie' , 'tutsplus' ),
'edit_item' => __( 'Edit Movie' , 'tutsplus' ),
'new_item' => __( 'New Movie' , 'tutsplus' ),
'view_item' => __( 'View Movie' , 'tutsplus' ),
'search_items' => __( 'Search Movies' , 'tutsplus' ),
'not_found' => __( 'No Movies Found' , 'tutsplus' ),
'not_found_in_trash' => __( 'No Movies found in Trash' , 'tutsplus' ),
);
$args = array(
'labels' => $labels,
'has_archive' => true,
'public' => true,
'hierarchical' => false,
'supports' => array(
'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes'
),
'rewrite' => array( 'slug' => 'movies' ),
'show_in_rest' => true
);
register_post_type( 'movies', $args );
}
add_action( 'init', 'tutsplus_register_post_type' );
Tested and works
