Post type and taxonomy registration not working in plugin but works in themes functions file

enter image description here
/* ---------------------------------------------- */
/* 1. Registering event Post Type */
/* ---------------------------------------------- */

add_action( 'init', 'create_event_cpt_taxonomy' );

function create_event_cpt_taxonomy() {
    register_taxonomy(
        'vcategory',
        'event',
        array(
            'label' => __( 'event Category', 'themedomain' ),
            'rewrite' => array( 'slug' => 'vcategory' ),
            'hierarchical' => true,
        )
    );
}

add_action( 'init', 'event_CPT_registration' );
/**
 * Register a event post type.
 *
 * @link http://codex.wordpress.org/Function_Reference/register_post_type
 */
function event_CPT_registration() {
    $labels = array(
        'name'               => _x( 'events', 'post type general name', 'themedomain' ),
        'singular_name'      => _x( 'event', 'post type singular name', 'themedomain' ),
        'menu_name'          => _x( 'events', 'admin menu', 'themedomain' ),
        'name_admin_bar'     => _x( 'event', 'add new on admin bar', 'themedomain' ),
        'add_new'            => _x( 'Add New', 'event', 'themedomain' ),
        'add_new_item'       => __( 'Add New event', 'themedomain' ),
        'new_item'           => __( 'New event', 'themedomain' ),
        'edit_item'          => __( 'Edit event', 'themedomain' ),
        'view_item'          => __( 'View event', 'themedomain' ),
        'all_items'          => __( 'All events', 'themedomain' ),
        'search_items'       => __( 'Search events', 'themedomain' ),
        'parent_item_colon'  => __( 'Parent events:', 'themedomain' ),
        'not_found'          => __( 'No events found.', 'themedomain' ),
        'not_found_in_trash' => __( 'No events found in Trash.', 'themedomain' )
    );

    $args = array(
        'labels'             => $labels,
        'description'        => __( 'The event Custom Post Type', 'themedomain' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'events' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
    );

    register_post_type( 'event', $args );
}

When I write the obove in themes functions.php than it works, but theme-check generates error. when I transfer it to a plugin’s functions.pho than it doesn’t work.I mean the event post type disappears.

what is going wrong. all the code written in shortcode.php is rendering, but the code written in the plugins functions.php is not rendering.

whats the Fix?

Read more here:: Post type and taxonomy registration not working in plugin but works in themes functions file

Leave a Reply

Your email address will not be published. Required fields are marked *