如果我对自定义帖子使用自定义类别,它的单个页面显示404错误,否则它在WordPress中运行良好

时间:2018-06-07 作者:Rajesh Sekar
<?php
/**
 * Updates Module custom post type
 */
add_action(\'init\', \'packages_post_type_register\');
function packages_post_type_register() {
    register_post_type( \'packages\' ,
                        array(
                            \'label\' => \'Packages\',
                            \'singular_label\' => \'Packages\',
                            \'public\' => true,
                            \'show_ui\' => true,
                            //\'menu_icon\' => get_stylesheet_directory_uri() . \'/images/testimonials-icon.png\', 
                            \'capability_type\' => \'post\',
                            \'hierarchical\' => false,
                            \'rewrite\' => true,
                            \'show_in_nav_menus\' => true,
                            \'supports\' => array(\'title\',\'thumbnail\', \'editor\')
                        )
                    );
    add_filter(\'manage_edit-packages_columns\', \'packages_edit_columns\');
    function packages_edit_columns($columns){
        $columns = array(
            \'cb\'    => \'<input type="checkbox" />\',
            \'title\' => \'packages\',
            \'author\'=> \'Author\',
            \'date\'  =>\'Date\'
        );
        return $columns;
    }
}
?>
<?php
/* Set up the taxonomies. */ 
add_action( \'init\', \'packages_taxonomies\', 0);
/* Registers taxonomies. */
function packages_taxonomies() { 
    /* Set up the artist taxonomy arguments. */ 
    $category_args = array( 
    \'hierarchical\' => true,
    \'query_var\' => true,
    \'show_ui\' => true,

    \'rewrite\' => array(
    \'slug\' => \'packages\'),
    \'labels\' => array(
    \'name\' => \'Category\',
    \'singular_name\' => \'Category\',
    \'edit_item\' => \'Edit Category\',
                    \'update_item\' => \'Update Category\',
                    \'add_new_item\' => \'Add New Category\',
                    \'new_item_name\' => \'New Category\',
                    \'all_items\' => \'All Categories\',
                    \'search_items\' => \'Search Category\',
                    \'parent_item\' => \'Parent Category\',
                    \'parent_item_colon\' => \'Parent Category:\',
                    ),
    );

    /* Register the technology taxonomy. */
    register_taxonomy( \'packages_category\', array( \'packages\'), $category_args );
    /* Adds the post_tag taxonomy to the page post type. */
    register_taxonomy_for_object_type( \'post_tag\', \'packages\'); 
}
?>
1 个回复
SO网友:Amol Kanherkar

post type和taxonomy的Slug相同请更改taxonomy的Slug。。。很抱歉,最初我没有检查您的代码。

结束

相关推荐