2016-07-27 7 views
0

私は、カスタムポストタイプエラーredicrect書き換えURLのカスタムポストタイプ

function anime_post_type() { 
 
    register_post_type('anime', array(
 
    'labels' => array(
 
     'name' => 'Anime', 
 
     'singular_name' => 'Anime', 
 
     'add_new' => _x('Thêm Anime', 'animefrost'), 
 
     'add_new_item' => 'Thêm Anime Mới', 
 
    ), 
 
    'show_ui' => true, 
 
    'public' => true, 
 
    'menu_icon' => 'dashicons-video-alt3', 
 
    'exclude_from_search' => true, 
 
    'hierarchical' => false, 
 
    'rewrite' => array('slug' => 'story', 'with_front' => FALSE), 
 
    'supports' => array('title', 'editor', 'thumbnail') 
 
    ) 
 
); 
 
    //flush_rewrite_rules(false); 
 
}

と私は私でhttp://localhost/Anime/story/one-pice/ep/1

http://localhost/Anime/story/one-pice/?ep=1を書き換えたいのHAVAコード

function add_query_vars_filter($vars){ 
 
    $vars[] = "ep"; 
 
    return $vars; 
 
} 
 
add_filter('query_vars', 'add_query_vars_filter'); 
 

 

 
add_action('init', 'dcc_rewrite_rules'); 
 
function dcc_rewrite_rules() { 
 
    add_rewrite_rule('^story/([^/]+)/ep/([0-9]+)$','index.php?post_type=anime&ep=$matches[2]','top'); 
 
    flush_rewrite_rules(false); 
 
}

私のコードのエラーは何ですか? お手数ですが、ありがとうございます。

答えて

0

add_filter('rewrite_rules_array', 'dcc_rewrite_rules'); 

今、あなたの新しいルールを追加し、それらを返すrewrite_rules_arrayフィルターであなたのルールを書き換え

function dcc_rewrite_rules() { 
    $aNewRules = array('story/([^/]+)/?$' => 'index.php?pagename=story&ep=$matches[1]'); 
    $aRules = $aNewRules + $aRules; 
    return $aRules; 
} 

チェックthis

はパーマリンク

を保存することを忘れないでください。でクエリ文字列にアクセスできます

+0

私は試していますが、is_frontページにリダイレクトされています –