I have registered a custom post type:
<?php
register_post_type( 'my_cpt_fiction',
array(
'labels' => array(
'name' => __( 'Custom Posts' )
, 'singular_name' => __( 'Custom Post' )
, 'add_new' => 'Add New'
, 'add_new_item' => 'Create a new Custom Post'
, 'edit' => 'Edit Custom Post'
, 'edit_item' => 'Edit Custom Post'
, 'new_item' => 'Create a new Custom Post,'
, 'view_item' => 'View Custom Post,'
, 'search_items' => 'Search Custom Post'
, 'not_found' => 'No Custom Posts found'
, 'not_found_in_trash' => 'No Custom Posts found in trash'
),
'public' => true
, 'has_archive' => true
, 'supports' => Array(
'title' => 'title'
, 'editor' => 'editor'
, 'author' => 'author'
, 'comments' => 'comments'
)
, 'show_ui' => true
, 'rewrite' => array( 'slug' => 'my_custom_post' , 'with_front' => false, 'feeds' => true )
, 'capability_type' => array('my_custom_post','my_custom_posts')
, 'map_meta_cap' => true
, 'taxonomies' => array('category')
, 'publicly_queryable' => true
, 'exclude_from_search' => false
, 'query_var' => true
)
);
I have no taxonomies.
This added to the menu, I can create and edit. But when I visit the link to the custom post, it doesn't load, instead I see the main static home page.
I have tried many different combinations of permalinks, or no permalinks.
I also cannot seem to find any information about specifically showing a custom post type AS IF it were a post or page, people just assume it must work...
Any help would be appreciated.
/J
This happens most of the time because of the WordPress rewrite rules, they are stored on Database and you need to flush them.
Go to Settings - Permalinks and just click save so you initiate flush rewrite rules.
Try wrapping it in the init hook:
add_action( 'init', 'create_my_post_type' );
function create_my_post_type() {
// Your code here
}
After creating the post type or changing it's rewrite settings, head over to your wordpress settings->permalinks and click save. This will reset your rewrite rules and recreate the .htaccess file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.