Moving 'register_post_type' to seperate file not working

I’m creating a simple plugin.
When I register a custom post type in the main plugin file it works, but when I move it to a seperate file, it doesn’t show up in the admin menu…

Portion main plugin file:

if ( ! defined( 'ABSPATH' ) ) {
    die( 'Access denied.' );

//Get some constants ready 
define( 'QD_KLANTEN_VERSION', '0.0.1' );
define( 'QD_KLANTEN_PATH', dirname( __FILE__ ) );
define( 'QD_KLANTEN_PATH_INCLUDES', dirname( __FILE__ ) . '/inc' );
define( 'QD_KLANTEN_FOLDER', basename( QD_KLANTEN_PATH ) );
define( 'QD_KLANTEN_URL', plugins_url() . '/' . QD_KLANTEN_FOLDER );

add_action( 'init', 'qdklanten_load_files' );
function qdklanten_load_files() {
    require_once( QD_KLANTEN_PATH_INCLUDES .'/qdklanten_cpt.php' );
    require_once( QD_KLANTEN_PATH_INCLUDES .'/qdklanten_settings.php' );

Inside qdklanten_cpt.php I register the CPT.. But it doesn’t show up in the admin menu.. After I ALSO try to register the CPT in the main file, I get a warning that the CPT with the same name is already loaded…. So apparently the register CPT runs on the second file, but not completely…?

My qdklanten_cpt.php file:

add_action( 'init', 'qdklanten_register_cpt' );
function qdklanten_register_cpt() {

    $labels = array(
        'name'               => 'QD Klanten',
        'singular_name'      => 'QD Klanten',
        'menu_name'          => 'QD Klanten',
        'name_admin_bar'     => 'QD Klanten',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Client',
        'new_item'           => 'New Client',
        'edit_item'          => 'Edit Client',
        'view_item'          => 'View Client',
        'all_items'          => 'All Clients',
        'search_items'       => 'Search Clients',
        'parent_item_colon'  => 'Parent Clients:',
        'not_found'          => 'No clients found.',
        'not_found_in_trash' => 'No clients found in Trash.'

    $args = array(
        'labels'             => $labels,
        'description'        => 'Description.',
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'qd-klanten' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
        //'register_meta_box_cb' => 'add_qdklantencpt_metaboxes'

    register_post_type( 'qdklanten', $args );  


Why is the register CPT working in the main file and not in a seperate file..? I also require_once a settings php file without any problems.

I removed all CPT inputs in the database.. Tried flush_rewrite_rules(); on the register_activation_hook..

Note, I get no php error, and with WP_DEBUG ON also no error’s.

I read everything about CPT in the WP codex, but I can’t find the solution there… Must be an easy fix though, but after a day i still can’t figure it out….

Please help 🙂


Solutions Collecting From Web of "Moving 'register_post_type' to seperate file not working"