3
votes

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 ) :

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:

2
Did you try to put flush_rewrite_rules( false ); just after?? also, what happens if you change permalink structure ? and do you have 'publicly_queryable' => true, - Obmerk Kronen
After adding 'publicly_queryable' => true & flush_rewrite_rules( false ); & cleared cache, still 404 Not Found... - Raptor
ok.. last thing that I can think of now is to try also 'rewrite' => array("slug" => "films","with_front" => true), combined with the others . I had the same problem about two weeks ago, but I can not remember just where the culprit was . and please post result of permalink structure change to default .. - Obmerk Kronen
Also - how do you access that page ? through a menu item ? - Obmerk Kronen
Add a new post in Custom Post through WordPress menu. Then click "View Post" - Raptor

2 Answers

0
votes

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.

0
votes

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.