カスタムポストタイプの「ショップ」を作成し、カスタム分類を作成します。 次に、各国ごとに新しいカスタム分類を追加し、それをカスタムの投稿タイプ「ショップ」に割り当てます。
そうのようなのfunctions.phpでカスタムポストタイプの登録:登録時に書き換えルールに%/%の国を使用するためには
add_action('init', 'build_taxonomies', 0);
function build_taxonomies() {
register_taxonomy('countries', 'shops', array('hierarchical' => true, 'label' => 'Countries', 'query_var' => true, 'rewrite' => array('slug' => 'shops', 'with_front' => false)));
}
:カスタム分類を登録すると
add_action('init', 'custom_post_types', 0);
function custom_post_types() {
//shops
register_post_type('shops',
array(
'labels' => array(
'name' => __('Shops'),
'singular_name' => __('Shops'),
'all_items' => __('All Shops'),
),
'capabilities' => array(
'edit_post' => 'update_core',
'read_post' => 'update_core',
'delete_post' => 'update_core',
'edit_posts' => 'update_core',
'edit_others_posts' => 'update_core',
'delete_posts' => 'update_core',
'publish_posts' => 'update_core',
'read_private_posts' => 'update_core'
),
'taxonomies' => array('countries'),
'menu_position' => 5,
'public' => true,
'has_archive' => false,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt'),
"rewrite" => array(
"slug"=>'news/%countries%',
"with_front" => false
),
)
);
}
をあなたのカスタム投稿タイプは、WordPressにその意味を伝える必要があります。あなたはそうそうする:
add_filter('post_type_link', 'wpa_shops_permalinks', 1, 2);
function wpa_shops_permalinks($post_link, $post){
if (is_object($post) && $post->post_type == 'shops'){
$terms = wp_get_object_terms($post->ID, 'countries');
if($terms){
return str_replace('%countries%' , $terms[0]->slug , $post_link);
}
}
return $post_link;
}