【问题标题】:Wordpress custom post type redirects me to postsWordpress 自定义帖子类型将我重定向到帖子
【发布时间】:2018-05-03 19:49:23
【问题描述】:

如果我在自定义帖子类型编辑页面上并单击菜单中的“编辑出版物”或“创建”链接,我总是会被重定向到一般帖子页面!

$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')
        );

如果我第一次进入 wp-admin 页面,或者我目前没有编辑任何帖子,则 url 不同并且工作正常

例如 目前我在仪表板页面上,“编辑出版物”的链接是

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

如果我在自定义帖子类型编辑页面上,“编辑出版物”的链接是

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

我不知道为什么 谢谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    试试这个

    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
    

    【讨论】:

    • 我遇到了同样的问题。在删除 rewrite 属性后工作,然后禁用并重新启用插件。
    猜你喜欢
    • 2020-10-24
    • 2016-04-27
    • 1970-01-01
    • 2016-11-29
    • 2011-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多