Custom Post 404

I’m attempting to create a custom post type (doctors) that will load a custom page template (single-doctors.php). I’ve set up the custom post type through functions.php, and created a ‘new doctor’, selected the single-doctors template.
But when I go to actually see the page, the template doesnt load and I’m presented with a “This page not found” page. I’ve been scouring the interwebs trying to find a solution to this. I find a lot of the same thing (flush permalinks, remove ‘has_archive’, etc.) but nothing has worked.

As a workaround, I tried downloading a custom post plugin (Custom Post Type UI) and setting things up that way. This worked!! But i will be doing more custom post creation on future sites and want to be able to do this without the plugin. I tried taking the code generated by the plugin itself and replacing my code with theirs in my functions.php file. This did not work and I was back to the “Page not found” page. I’m pulling my hair out. Can anybody help me identify what puzzle piece I’m missing? Any help is greatly appreciated. My functions.php code and the plugin’s code below…

My code:

// Doctors
add_action( ‘init’, ‘doctors_init’ );
function doctors_init() {
$labels = array(
‘name’ => _x( ‘Doctors’, ‘post type general name’, ‘AIN’ ),
‘singular_name’ => _x( ‘Doctor’, ‘post type singular name’, ‘AIN’ ),
‘menu_name’ => _x( ‘Doctors’, ‘admin menu’, ‘AIN’ ),
‘name_admin_bar’ => _x( ‘Doctor’, ‘add new on admin bar’, ‘AIN’ ),
‘add_new’ => _x( ‘Add New’, ‘Doctor’, ‘AIN’ ),
‘add_new_item’ => __( ‘Add New Doctor’, ‘AIN’ ),
‘new_item’ => __( ‘New Doctor’, ‘AIN’ ),
‘edit_item’ => __( ‘Edit Doctor’, ‘AIN’ ),
‘view_item’ => __( ‘View Doctor’, ‘AIN’ ),
‘all_items’ => __( ‘All Doctors’, ‘AIN’ ),
‘search_items’ => __( ‘Search Doctors’, ‘AIN’ ),
‘parent_item_colon’ => __( ‘Parent Doctors:’, ‘AIN’ ),
‘not_found’ => __( ‘No Doctors found.’, ‘AIN’ ),
‘not_found_in_trash’ => __( ‘No Doctors found in Trash.’, ‘AIN’ )
);

$args = array(
“label” => __( “doctors”, “understrap-child” ),
‘labels’ => $labels,
‘description’ => __( ‘Description.’, ‘AIN’ ),
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘doctors’, “with_front” => true ),
‘capability_type’ => ‘post’,
‘has_archive’ => false,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘comments’ ),
‘menu_icon’ => ‘dashicons-groups’,
);
register_post_type( ‘doctors’, $args );
}

Plugin’s Code:

function cptui_register_my_cpts_doctors2() {

/**
* Post Type: doctors2.
*/

$labels = array(
“name” => __( “doctors2”, “understrap-child” ),
“singular_name” => __( “doctor2”, “understrap-child” ),
);

$args = array(
“label” => __( “doctors2”, “understrap-child” ),
“labels” => $labels,
“description” => “”,
“public” => true,
“publicly_queryable” => true,
“show_ui” => true,
“show_in_rest” => false,
“rest_base” => “”,
“has_archive” => false,
“show_in_menu” => true,
“exclude_from_search” => false,
“capability_type” => “post”,
“map_meta_cap” => true,
“hierarchical” => false,
“rewrite” => array( “slug” => “doctors2”, “with_front” => true ),
“query_var” => true,
“supports” => array( “title”, “editor”, “thumbnail” ),
);

register_post_type( “doctors2”, $args );
}

add_action( ‘init’, ‘cptui_register_my_cpts_doctors2’ );

Any help or guidance is greatly appreciated. Thanks!

Read more here:: Custom Post 404

Leave a Reply

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