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:
-
add
publicly_queryable
with valuetrue
to options array ( it’s not required, aspublic
is already set totrue
and default value ofpublicly_queryable
is equal to the value ofpublic
) -
add
with_front
with valuetrue
torewrite
sub-array ( *it’s not required too, as the default value ofwith_front
istrue
) -
add
flush_rewrite_rules(false);
afterregister_post_type()
All the above tries have no effect. Cache is already disabled & flushed.
Reference Questions:
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.
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:To disable this lock, change the value in the virtual host file ( in
sites-enabled
folder ) to:then restart Apache.