【发布时间】:2016-02-12 09:12:03
【问题描述】:
我正在制作一个插件,我在其中检测选定的自定义字段。如果用户在自定义字段中选择了男孩,则 url 往往是 www.example.com/boys/shirts 如果用户选择女孩,则 url 往往是 www.example.com/girls/top。问题是 wordpress rewite 每次只适用于一种情况。更改选项并保存帖子后,我清除了永久链接的设置。带有
的网址 if($model_type=="boys") {
$labels = array(
'name' => _x( 'Boys', 'Post Type General Name', $txtdomain ),
'singular_name' => _x( 'Boy', 'Post Type Singular Name', $txtdomain ),
'menu_name' => __( 'Models', $txtdomain ),
'parent_item_colon' => __( 'Parent Model', $txtdomain ),
'all_items' => __( 'All Models', $txtdomain ),
'view_item' => __( 'View Model', $txtdomain ),
'add_new_item' => __( 'Add New Model', $txtdomain ),
'add_new' => __( 'New Model', $txtdomain ),
'edit_item' => __( 'Edit Model', $txtdomain ),
'update_item' => __( 'Update Model', $txtdomain ),
'search_items' => __( 'Search models', $txtdomain ),
'not_found' => __( 'No models found', $txtdomain ),
'not_found_in_trash' => __( 'No models found in Trash', $txtdomain ),
);
$this->args = array(
'description' => __( 'Models-boys', $txtdomain ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_icon' => trailingslashit( $uri ) . 'images/model-icon.png',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array( 'slug' => 'boys' )
);
} else {
$labels = array(
'name' => _x( 'Girls', 'Post Type General Name', $txtdomain ),
'singular_name' => _x( 'Girl', 'Post Type Singular Name', $txtdomain ),
'menu_name' => __( 'Models', $txtdomain ),
'parent_item_colon' => __( 'Parent Model', $txtdomain ),
'all_items' => __( 'All Models', $txtdomain ),
'view_item' => __( 'View Model', $txtdomain ),
'add_new_item' => __( 'Add New Model', $txtdomain ),
'add_new' => __( 'New Model', $txtdomain ),
'edit_item' => __( 'Edit Model', $txtdomain ),
'update_item' => __( 'Update Model', $txtdomain ),
'search_items' => __( 'Search models', $txtdomain ),
'not_found' => __( 'No models found', $txtdomain ),
'not_found_in_trash' => __( 'No models found in Trash', $txtdomain ),
);
$this->args = array(
'description' => __( 'Models-mens', $txtdomain ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_icon' => trailingslashit( $uri ) . 'images/model-icon.png',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array( 'slug' => 'girls' )
);
}
女孩们正在工作并打开single.php,但男孩们打开了未找到的页面。
【问题讨论】: