Custom Permalink of Custom Post Type

I register a new Custom Post Type with:

register_post_type('abcd_film',
    array(
        'labels' => array(
            'name' => __( 'Films' ),
            'singular_name' => __( 'Film' )
        ),
        'description'   => 'Manage the Films',
        'supports'      => array( 'title', 'editor', 'custom-fields', ),
        'public'        => true,
        'has_archive'   => true,
        'rewrite'       => array('slug' => 'films'),
    )
);

My WordPress is located at ( dummy link ) :

Read More

www.example.com/folder/wordpress/

My permalink setting is ( the “Post Name” option ):

www.example.com/folder/wordpress/%postname%/

However, I create a new custom post under the custom post type “Films” with post name “Apple”, the link shows 404 File Not Found. The .htaccess file is writable by WordPress & the current content written by WordPress is:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /folder/wordpress/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /folder/wordpress/index.php [L]
</IfModule>

# END WordPress

I double checked with phpinfo(), the mod_rewrite() module is in “Loaded Module” section. Also, I tried to refresh the Permalink settings in WordPress Admin > General > Permalink > Save Changes.

404 Not Found still persists. What else can I do?

Tried the followings:

  1. add publicly_queryable with value true to options array ( it’s not required, as public is already set to true and default value of publicly_queryable is equal to the value of public )

  2. add with_front with value true to rewrite sub-array ( *it’s not required too, as the default value of with_front is true )

  3. add flush_rewrite_rules(false); after register_post_type()

All the above tries have no effect. Cache is already disabled & flushed.

Reference Questions:

Related posts

Leave a Reply

2 comments

  1. If you are using Chrome to test this you will want to make sure your browser cache is emptied. Use the Chrome menu to empty the cache. This has bitten me more than once. I clear the cache, exit Chrome, re-access the site.

    I’ve also had issues with Save Changes on permalinks not flushing the permalinks table. Change to the default post ID post type than back to your normal post type.

    The other issue I’ve run into with my customer base is a WordPress theme that is augmenting the permalink rules. If not done correctly it can cause custom post types to malfunction. Try a default WordPress theme like Twenty Thirteen.

    If all else fails start with a test site with a clean WordPress 3.6 install, add your custom post type and NOTHING else (no theme changes or extra plugins). That will eliminate all other variables and let you focus on server and system rules. Seems like you’ve already ruled that out, however.

    Good luck & remember to share your answer if you find it on your own.

  2. The issue is not due to WordPress configuration or PHP configuration. The reason of .htaccess not working is: In my Apache virtual host settings, it is configured to ignore .htaccess by:

    AllowOverride None
    

    To disable this lock, change the value in the virtual host file ( in sites-enabled folder ) to:

    AllowOverride All
    

    then restart Apache.