2016-08-12 7 views
1

私はカスタムポストタイプを作成しました。コレクション以下のコードを参照してください。URLの最後にあるWordpress CPTの余分なパラメータ - > 404

`$labels = array(
     'name' => __('Collections', 'pcs'), 
     'singular_name' => __('Collection', 'pcs'), 
     'add_new' => __('New Collection', 'pcs'), 
     'add_new_item' => __('New Collection', 'pcs'), 
     'edit_item' => __('Edit Collection', 'pcs'), 
     'new_item' => __('New Collection', 'pcs'), 
     'view_item' => __('View Collection', 'pcs'), 
     'search_items' => __('Search Collections', 'pcs'), 
     'not_found' => __('No Collection Found', 'pcs'), 
     'not_found_in_trash' => __('No Collection Found in Trash', 'pcs'), 
     'parent_item_colon' => __('Parent Collection', 'pcs'), 
     'menu_name' => __('All Collections', 'pcs'), 
     'filter_items_list' => __('Filter collections list', 'pcs'), 
     'items_list_navigation' => __('Collections list navigation', 'pcs'), 
     'items_list' => __('Collections list', 'pcs') 
    );` 

    $args = array(
     'labels' => $labels, 
     'hierarchical' => false, 
     'supports' => array('title'), 
     'public' => true, 
     'show_ui' => true, 
     'show_in_nav_menus' => false, 
     'show_in_menu' => 'pcs', 
     'menu_position' => 1, 
     'publicly_queryable' => true, 
     'exclude_from_search' => true, 
     'has_archive' => false, 
     'query_var' => true, 
     'can_export' => true, 
     'rewrite' => array(
      'slug' => 'collections'), 
      'with_front' => false 
     ), 
     'capability_type' => 'post' 
    ); 

魅力的な作品です。 私は、このページに移動する場合:http://www.example.com/collections/slug

それは私にフックへのテンプレートのおかげを示しています

function xload_template($single_template) { 

    global $post; 

    if ($post->post_type == 'my_collection') { 
     if (file_exists(PATH . 'frontend/template.php')) { 
      $single_template = PATH . 'frontend/template.php'; 
     } 
    } 

    return $single_template; 
} 

add_filter('single_template', 'xload_template'); 

問題は、私はこのような余分な変数トラフにURLを渡したい、次のとおりです。http://www.example.com/collection/slug/email_md5

コレクションを表示するための確認としてemail_hashを使用できます。私はルールを書き直さなければならないことを知っていますが、それを動作させることはできません。

function add_rewrite_rules($aRules) { 
    $aNewRules = array('collections/([^/]+)/([^/]+)/?$' => 'index.php?collections=$matches[1]&email=$matches[2]','top'); 
    $aRules = $aNewRules + $aRules; 
    return $aRules; 
} 

add_filter('rewrite_rules_array', 'add_rewrite_rules'); 

FIX:私はWordpressのプラグインから以内にカスタムポストタイプにかなり新しいだったので、私はあなたがWordpressのが何をしているかを知っていれば、リライトを作成するためにはるかに簡単だった考え出しました。あなたのwordpress設定を変更する - > Permalinks - > Plain。 このようにして、URLの呼び出し方法と、独自の書き換え内での使用方法を確認できます。以下の答えは私のためにそれを解決しました。ありがとう

答えて

1

あなたが探しているものはadd_rewrite_ruleだと思います。あなたは次のようなものを試すことができます。

function custom_rewrite_rule() { 
    add_rewrite_rule('collections/([^/]+)/([^/]+)/?$','index.php?collections=$matches[1]&email=$matches[2]','top'); 
    } 
    add_action('init', 'custom_rewrite_rule', 10, 0); 
関連する問題