Custom Post Type Not Working
-
I am making a new theme and need a custom post type for “Books”. I used this website to generate the custom post type code for the
functions.php
file.While the list of “Books” works fine, for some reason I keep getting a 404 error for the single “Books” page. I followed the instructions on the WordPress Codex site in terms of naming the file (
single-mj_books.php
) but it still isn’t working.Here is my
functions.php
code:class mj_books { function mj_books() { add_action('init',array($this,'create_post_type')); } function create_post_type() { $labels = array( 'name' => 'Books', 'singular_name' => 'Book', 'add_new' => 'Add New', 'all_items' => 'All Books', 'add_new_item' => 'Add New Book', 'edit_item' => 'Edit Book', 'new_item' => 'New Book', 'view_item' => 'View Book', 'search_items' => 'Search Books', 'not_found' => 'No Books found', 'not_found_in_trash' => 'No Books found in trash', 'parent_item_colon' => 'Parent Books:', 'menu_name' => 'Books' ); $args = array( 'labels' => $labels, 'description' => "", 'public' => true, 'exclude_from_search' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_in_menu' => true, 'show_in_admin_bar' => true, 'menu_position' => 20, 'menu_icon' => null, 'capability_type' => 'post', 'hierarchical' => true, 'supports' => array('title','editor','thumbnail'), 'has_archive' => false, 'rewrite' => array('slug' => 'books'), 'query_var' => true, 'can_export' => true ); register_post_type('mj_books',$args); } } $mj_books = new mj_books();
Is there something I am doing wrong? Please help. Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom Post Type Not Working’ is closed to new replies.