简体   繁体   中英

Wordpress custom post type redirects me to posts

if i'm on the custom post type edit page and click either "Edit Publications" or "Create" link in the menu i always get redirected to the general posts page!

$labels = array(
            'name'               => 'Edit Publications',
            'singular_name'      => 'Edit Publications',
            'edit_item'          => 'Edit Publications'
        );
        $args = array(
            'labels'            => $labels,
            'public'            => true,
            'publicly_queryable'=> true,
            'show_ui'           => true,
            'show_in_nav'       => true,
            'query_var'         => true,
            'map_meta_cap'      => true,
            'hierarchical'      => false,
            'supports'          => array(''),
            'has_archive'       => true,
            'rewrite'           => array('slug' => 'publication')
        );

if i enter the wp-admin page the first time or i'm currently not editing any post the url is different and is working fine

eg currently i'm on the dashboard page and the link to "Edit Publications" is

http://example.com/wp-admin/edit.php?post_type=mfl_publication

if i'm on the custom post type edit page the link to "Edit Publications" is

http://example.com/wp-admin/post.php/edit.php?post_type=mfl_publication

i've no idea why thanks

try this

function create_example()
{
    register_taxonomy_for_object_type('category', 'example'); // Register Taxonomies for Category
    register_taxonomy_for_object_type('post_tag', 'example');
    register_post_type('example', // Register Custom Post Type
        array(
            'labels' => array(
                'name' => __('example', 'example'), // Rename these to suit
                'singular_name' => __('Comunicado', 'example'),
                'add_new' => __('Add New', 'example'),
                'add_new_item' => __('Add New Comunicado', 'example'),
                'edit' => __('Edit', 'example'),
                'edit_item' => __('Edit Comunicado', 'example'),
                'new_item' => __('New Comunicado', 'example'),
                'view' => __('View Comunicado', 'example'),
                'view_item' => __('View Comunicado', 'example'),
                'search_items' => __('Search Comunicado', 'example'),
                'not_found' => __('Nothing Found', 'example'),
                'not_found_in_trash' => __('Nothing Found in Trash', 'example')
            ),
            'public' => true,
            'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
            'has_archive' => true,
            'supports' => array(
                'title',
                'thumbnail'
            ), // Go to Dashboard Custom HTML5 Blank post for supports
            'can_export' => true, // Allows export in Tools > Export
            'taxonomies'  => array( 'category' )
        ));
}


add_action('init', 'create_example'); // Add our HTML5 Blank Custom Post Type

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM