我为自定义帖子类型创建了自定义分类法。
function create_states_hierarchical_taxonomy() {
$labels = array(
\'name\' => _x( \'States\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'State\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search States\' ),
\'all_items\' => __( \'All States\' ),
\'parent_item\' => __( \'Parent State\' ),
\'parent_item_colon\' => __( \'Parent State:\' ),
\'edit_item\' => __( \'Edit State\' ),
\'update_item\' => __( \'Update State\' ),
\'add_new_item\' => __( \'Add New State\' ),
\'new_item_name\' => __( \'New State Name\' ),
\'menu_name\' => __( \'States\' ),
);
// Now register the taxonomy
register_taxonomy(\'states\',array(\'post\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'states\' ),
));
}
我有3种自定义帖子类型。它们都很相似。这就是其中之一。
// Speech Language Pathologists custom post
function create_pathologists() {
$labels = array (
\'name\' => \'Pathologists\',
\'singular_name\' => \'Pathologist\',
\'add_new\' => \'Add SLP\',
\'all_items\' => \'All SLPs\',
\'add_new_item\' => \'Add SLP\',
\'edit_item\' => \'Edit SLP\',
\'new_item\' => \'New SLP\',
\'view_item\' => \'View SLP\',
\'search_item\' => \'Search SLPs\',
\'not_found\' => \'No SLPs found\',
\'not_found_in_trash\' => \'No SLPs found in trash\',
\'parent_item_colon\' => \'Parent Item\'
);
$args = array (
\'labels\' => $labels,
\'public\' => true,
\'show_in_menu\' => true,
\'has_archive\' => true,
\'publicly_queryable\' => true,
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'pathologists/%states%\',
\'with_front\' => false,
),
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'supports\' => array (
\'title\',
\'editor\',
\'excerpt\',
\'thumbnail\',
\'revisions\',
),
\'taxonomies\' => array (\'states\', \'post_tag\'),
\'exclude_from_search\' => false
);
register_taxonomy_for_object_type( \'states\', \'create_schools\' );
register_taxonomy_for_object_type( \'post_tag\', \'create_schools\' );
register_post_type(\'pathologists\', $args);
}
add_action( \'init\', \'create_pathologists\' );
我过滤permalink,使其在自定义帖子类型名称之后、帖子名称之前显示分类名称。
add_filter(\'post_type_link\', \'pathologists_permalink_structure\', 10, 4);
function pathologists_permalink_structure($post_link, $post, $leavename, $sample)
{
$post = get_post($id);
if ( false !== strpos( $post_link, \'%states%\' ) ) {
$state_term = get_the_terms( $post->ID, \'states\' );
$post_link = str_replace( \'%states%\', array_pop( $state_term )->slug, $post_link );
}
return $post_link;
}
flush_rewrite_rules();
例如,我在病理学家和阿拉巴马分类下有一篇文章,名为“测试”。permalink如下所示:
http://sitename/pathologists/alabama/test/
因此,我可以访问任何页面,没有任何问题,但在按状态显示特定自定义帖子类型的所有帖子时,WP使用默认存档。php并显示所有自定义帖子类型中特定状态的所有帖子。
我查看了
solution 由彼得·古森(PieterGoosen)提出,但我所做的任何尝试都不会给我正确的结果。
我尝试使用的所有可能文件包括:
病理学家档案馆。php表示。阿拉巴马州。菲律宾阿拉巴马州。php分类状态。php分类法状态。php是迄今为止我能得到的最接近的。至少它使用了正确的模板。但它并没有向我显示单一自定义帖子类型中的所有状态帖子,而是向我显示了我在自定义帖子字段中输入的专家的3个姓名,这是我首先尝试使用的自定义帖子类型UI插件。插件与所有帖子和类型一起被删除。
一、 此外,尝试使用category\\u模板将我的内容显示在我想要的特定页面上,但也没有成功。
我觉得一个问题的解决方案非常接近,但我再也想不出来了。请帮帮我
问题的实时版本为here