WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having a hard time implementing a custom post type correctly. I have searched for a solution for a long time but couldn't find any. Here's what I did:

  1. Freshly installed WordPress in my local wamp server (enabled apache rewrite_module first).

  2. Using default theme (twenty fourteen). No plugins installed.

  3. Changed permalinks to "Post name"

  4. In the plugins folder, created a folder named pr_custom_posts and inside that, created a file named pr_custom_posts.php. In the file I created a custom post type. The code is as follows:

    * Plugin Name: PR Movies Custom Post
    * Plugin URI: http://www.example.com
    * Description: Learning Custom Posts
    * Author: PR
    * Author URI: http://www.example.com
    * Version: 1.0
    class PR_Movies_Custom_Post {
    public function __construct() {
    public function register_post_type () {
        $args = array(
            'labels' => array (
                'name' => 'Movies',
                'singular_name' => 'Movie',
                'add_new' => 'Add New Movie',
                'add_new_item' => 'Add New Movie',
                'edit_item' => 'Edit Movie',
                'new_item' => 'Add New Movie',
                'view_item' => 'View Movie',
                'search_items' => 'Search Movies',
                'not_found' => 'No Movies Found',
                'not_found_in_trash' => 'No Movies Found in Trash'
            'query_var' => 'movies',
            'rewrite' => array (
                'slug' => 'movies/',
                'with_front'=> false
            'public' => true,
            'publicly_queryable' => true,
            'has_archive' => true,
            'menu_position' => 10,
            'menu_icon' => admin_url().'/images/media-button-video.gif',
            'supports' => array (
        register_post_type('pr_movie', $args);
     add_action('init', function() {
    new PR_Movies_Custom_Post();

The Good Thing: The CPT is showing in my admin panel and I can add and view movies there.

THE PROBLEM: I cannot preview the movies in the front end (By clicking the "view" in the CPT in admin panel). It shows in the front end only when I set permalink to default (http://localhost/wp02/?p=123).

What I have tried:

  1. Go to permalink, keep permalink settings to "Post name" and Save changes.

  2. Use flush_rewrite_rules() in several places (one by one) in my code. Please see the commented out parts in the code above.

  3. Created a menu item as: URL: http://localhost/wp02/movies Navigation Label: Movies This creates a menu item in the front end but shows "Not Found" when "Movies" link is clicked.

This is driving me crazy. Can anyone please help on this? I would really appreciate.

share|improve this question
Why you've added / in rewrite slug, replace that slash after movies and reflush the rewrite rules and you are good to go. – Anjum Jun 29 '14 at 11:34
@Anjum Thanks for your perfect solution. I was following a tutorial where / was added in the rewrite slug. Thanks again. – user2407971 Jun 30 '14 at 8:08
@Anjum please post that as an answer, so it can be properly accepted and visible as such :) – Rarst Jun 30 '14 at 8:57

Thanks to Anjum for his suggestion in the comments. The problem has been solved by removing the front-slash in the rewrite slug. The error was caused by:

'rewrite' => array (
    'slug' => 'movies/',
    'with_front'=> false

The error has been solved by the following modification:

'rewrite' => array (
    'slug' => 'movies',
    'with_front'=> false
share|improve this answer
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – ialocin Jun 30 '14 at 8:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.