解析为附件的自定义帖子类型

时间:2011-12-05 作者:Dipesh KC

我几乎没有自定义的帖子类型,在单个帖子上我得到了404错误页面。我想我已经尝试了网上发布的几乎所有解决方案,但它仍然不适合我,我开始觉得我犯了一些其他的错误。当我尝试调试时,我发现我的每个自定义帖子都被解析为“附件”。请帮我弄清楚我犯了什么错误。

function jnj_register_board_members_posttype ()
{

    $labels = array ( 
        \'name\' => _x ( \'Board Members\' , \'jnj\' ) , 
        \'singular_name\' => _x ( \'Board Member\' , \'jnj\' ) , 
        \'add_new\' => _x ( \'New Member\' , \'jnj\' ) , 
        \'add_new_item\' => __ ( \'New Board Member\' , \'jnj\' ) , 
        \'edit_item\' => __ ( \'Edit\' , \'jnj\' ) , 
        \'new_item\' => __ ( \'New Board Member \' ) , 
        \'all_items\' => __ ( \'All Board Members\' ) , 
        \'view_item\' => __ ( \'View Board Member\' ) , 
        \'search_items\' => __ ( \'Search Board Members\' ) , 
        \'not_found\' => __ ( \'No Board Members found\' ) , 
        \'not_found_in_trash\' => __ ( \'Board Member not found in Trash\' ) , 
        \'parent_item_colon\' => \'\' , 
        \'menu_name\' => \'Board Member\' )

    ;
    $args = array ( 
        \'labels\' => $labels , 
        \'public\' => true , 
        \'publicly_queryable\' => true , 
        \'show_ui\' => true , 
        \'show_in_menu\' => true , 
        \'query_var\' => true , 
        \'rewrite\' => array( \'slug\' => \'board-members\', \'with_front\' => false),
        \'capability_type\' => \'post\' , 
        \'hierarchical\' => false , 
        \'menu_position\' => 5 , 
        \'menu_icon\' => get_stylesheet_directory_uri ( ) . \'/images/board-members.png\' ,  
        \'register_meta_box_cb\'=>\'register_board_members_metabox\',
        \'taxonomies\' => array ( \'jnj_title\' ) , 
        \'supports\' => array ( \'title\' , \'editor\' , \'thumbnail\' , \'custom-fields\' , \'excerpt\' ) )
    ;

    register_post_type ( \'board_members\' , $args );

}
add_action(\'init\', \'jnj_register_board_members_posttype\');

1 个回复
SO网友:Dipesh KC

最后我自己找到了解决办法。如果您也有类似的问题,请添加以下两行

  global $wp_rewrite;
  $wp_rewrite->flush_rules(); 

结束

相关推荐

Permalinks Won't Work

由于某种原因,永久物不会起作用。我单击选项3的单选按钮,然后单击保存,但它会返回到选项1。发生什么事了?(这不应该是FTP问题-它有本地主机访问数据库的权限,我可以在Wordpress fine中下载插件。)