2016-07-27 1 views
0

I 하바 사용자 정의 포스트 유형오류 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=1http://localhost/Anime/story/one-pice/ep/1

을 다시 할 내 코드

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 페이지로 리디렉션됩니다. –

관련 문제