分类学页面转到404 pgae

时间:2017-08-04 03:50:33

标签: wordpress custom-post-type

我正在使用Redux Framework创建一个自定义帖子类型。直接按类别创建类别和类别视图直接转到链接,但该链接应直接转到404页面。请检查下面的代码,并告诉我代码中的错误。

remove_action( 'init', 'brightness_service_register',10 );
add_action( 'init', 'brightness_service_register',1 ); 
function brightness_service_register()
{
$labels = array(
'name' => __( 'Service', 'brightness' ),
'add_new' => __( 'Add New', 'brightness' ),
'add_new_item' => __( 'Add New Service', 'brightness'),
'edit_item' => __( 'Edit Service', 'brightness'),
'new_item' => __( 'New Service', 'brightness' ),
'view_item' => __( 'View Service', 'brightness' ),
'search_items' => __( 'Search Service', 'brightness' ),
'not_found' => __( 'No items found', 'brightness' ),
'not_found_in_trash' => __( 'No items found in Trash', 'brightness' ), 
'parent_item_colon' => '',
'menu_name' => 'Service'
);
$args = array(
'labels' => $labels,
'menu_icon' => 'dashicons-images-alt2',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'rewrite' => array( 'slug' => 'service', 'with_front' => false ),
'exclude_from_search' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes'
));
$taxonomy_labels = array(
  'name' => __( 'Service Categories', 'taxonomy general name' ),
  'singular_name' => __( 'Service Category', 'taxonomy singular name' ),
  'search_items' =>  __( 'Search Category' ),
  'all_items' => __( 'All Service Categories' ),
  'parent_item' => __( 'Parent Service Category' ),
  'parent_item_colon' => __( 'Parent Location:' ),
  'edit_item' => __( 'Edit Category' ),
  'update_item' => __( 'Update Category' ),
  'add_new_item' => __( 'Add New Category' ),
  'new_item_name' => __( 'New Category Name' ),
  'menu_name' => __( 'Service Categories' ),
); 
$taxonomy_args = array(
'hierarchical' => true,
'labels' => $taxonomy_labels,
'rewrite' => array(
  'slug' => 'service-categories', // This controls the base slug that will display before each term
  'with_front' => false, // Don't display the category base before "/locations/"
  'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"),); 
register_post_type( 'service' , $args );
register_taxonomy('coll-categories', 'service',$taxonomy_args);
} 

3 个答案:

答案 0 :(得分:0)

基于wordpress codex,您需要使用register_taxonomy_for_object_type将自定义帖子类型和自定义分类法互连到be sage than sorry。因此,我认为在调用register_taxonomy行后添加此内容可能会为您解决此问题。

register_taxonomy_for_object_type( 'coll-categories', 'service' );

答案 1 :(得分:0)

当我将你的代码片段粘贴到数组中时,你已经完成了一切,你需要结束你的数组$ taxonomy_args

你的答案 注册自定义分类后,您可以添加SELECT "KPMID", "CustomerID" as "cust_id::multi-filter", "KPM_Name", "Report_Period" as "rep_id::multi-filter", '<input type="text" ng-model="$select.search"/>' "Actual", CASE WHEN "TrendCode" = 'R' THEN '<img src="http://34.213.131.167/images/red.png" height="20px" width="100px"/>' WHEN "TrendCode" = 'Y' THEN '<img src="http://34.213.131.167/images/yellow.png" height="20px" width="100px"/>' ELSE '<img src="http://34.213.131.167/images/green.png" height="20px" width="100px""/>' END "TrendCode", CASE WHEN "CStatusCode" = 'R' THEN '<img src="http://34.213.131.167/images/red.png" height="20px" width="100px"/>' WHEN "CStatusCode" = 'Y' THEN '<img src="http://34.213.131.167/images/yellow.png" height="20px" width="100px"/>' ELSE '<img src="http://34.213.131.167/images/green.png" height="20px" width="100px""/>' END "CStatusCode", CASE WHEN "OutlookCode" = 'R' THEN '<img src="http://34.213.131.167/images/red.png" height="20px" width="100px"/>' WHEN "OutlookCode" = 'Y' THEN '<img src="http://34.213.131.167/images/yellow.png" height="20px" width="100px"/>' ELSE '<img src="http://34.213.131.167/images/green.png" height="20px" width="100px""/>' END "OutlookCode" FROM public."KPMDataReport";

  

注意:仅在激活或取消激活时刷新规则,或者当您知道需要更改重写规则时。不要在任何常规触发的钩子上做这件事。 WP工程师帖子评论中的更多详细信息:自定义帖子类型和永久链接

您可以转到设置→永久链接→保存永久链接,这应该手动刷新重写规则。

参考文献 https://wordpress.stackexchange.com/questions/250222/custom-taxonomy-leads-to-404-page

答案 2 :(得分:0)

add_action( 'init', 'brightness_service_register',0); 
function brightness_service_register()
{

$labels = array(
'name' => __( 'Service', 'brightness' ),
'add_new' => __( 'Add New', 'brightness' ),
'add_new_item' => __( 'Add New Service', 'brightness'),

    'edit_item' => __( 'Edit Service', 'brightness'),
    'new_item' => __( 'New Service', 'brightness' ),
    'view_item' => __( 'View Service', 'brightness' ),
    'search_items' => __( 'Search Service', 'brightness' ),
    'not_found' => __( 'No items found', 'brightness' ),
    'not_found_in_trash' => __( 'No items found in Trash', 'brightness' ), 
    'parent_item_colon' => '',
    'menu_name' => 'Service'
);
$args = array(
    'labels' => $labels,
    'menu_icon' => 'dashicons-images-alt2',
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'capability_type' => 'post',
    'has_archive' => true,
    'hierarchical' => false,
    'rewrite' => array( 'slug' => 'service' ),
    'exclude_from_search' => true,
    'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes'
));
$taxonomy_labels = array(
      'name' => __( 'Service Categories', 'taxonomy general name' ),
      'singular_name' => __( 'Service Category', 'taxonomy singular name' ),
      'search_items' =>  __( 'Search Category' ),
      'all_items' => __( 'All Service Categories' ),
      'parent_item' => __( 'Parent Service Category' ),
      'parent_item_colon' => __( 'Parent Location:' ),
      'edit_item' => __( 'Edit Category' ),
      'update_item' => __( 'Update Category' ),
      'add_new_item' => __( 'Add New Category' ),
      'new_item_name' => __( 'New Category Name' ),
      'menu_name' => __( 'Service Categories' ),
    ); 
$taxonomy_args = array(
    'labels' => $taxonomy_labels,
    'hierarchical'          => true,
    'show_ui'               => true,
    'show_admin_column'     => true,
    'query_var'             => true,
    'rewrite' => array('slug' => 'service-categories', 'with_front' => false)
);
register_post_type( 'service' , $args );
register_taxonomy('service-categories', 'service',$taxonomy_args);
flush_rewrite_rules();

}