WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Post Type Plugin 404 Error (3 posts)

  1. ajcke
    Member
    Posted 1 year ago #

    I've created a custom post type plugin (following a tutorial). When I add a new post and then view the post I get a 404 error. Below is the code in the plugin.

    add_action( 'init', 'create_movie_review' );
    function create_movie_review() {
        register_post_type( 'movie_reviews',
            array(
                'labels' => array(
                    'name' => 'Movie Reviews',
                    'singular_name' => 'Movie Review',
                    'add_new' => 'Add New',
                    'add_new_item' => 'Add New Movie Review',
                    'edit' => 'Edit',
                    'edit_item' => 'Edit Movie Review',
                    'new_item' => 'New Movie Review',
                    'view' => 'View',
                    'view_item' => 'View Movie Review',
                    'search_items' => 'Search Movie Reviews',
                    'not_found' => 'No Movie Reviews found',
                    'not_found_in_trash' => 'No Movie Reviews found in Trash',
                    'parent' => 'Parent Movie Review'
                ),
    
                'public' => true,
                'menu_position' => 15,
                'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),
                'taxonomies' => array( '' ),
                'menu_icon' => plugins_url( 'my-photo-sessions/camera.png', __FILE__ ),
                'has_archive' => true
            )
        );
    }
  2. catacaustic
    Member
    Posted 1 year ago #

    I've found that a lot of times you need to reset your permalinks when you add a new custom post type because it doesn't update WordPress's internal routing without doing that. Just go to 'Settings -> Permalinks' and change to 'Default' then back to what you have set now and try again and it should work.

  3. ajcke
    Member
    Posted 1 year ago #

    Thanks! That did the trick.

Topic Closed

This topic has been closed to new replies.

About this Topic