我不知道这是否有助于您使用插件创建自定义的帖子类型和分类法(从来没有像这样)。这就是我的开发人员从自定义分类中获取帖子,以便在slug匹配时显示在自定义帖子页面上。与您所做的相似,但技术上相反。。。
In Functions.php...
Create custom post type to custom taxonomy relation
global $post_tax;
$post_tax = array(
\'store\' => array(\'post\' => \'stores\', \'tax\' => \'store\'),
\'state\' => array(\'post\' => \'states\', \'tax\' => \'state\')
);
Register post types
function post_types_custom_init() {
global $post_tax;
register_post_type($post_tax[\'store\'][\'post\'], array(\'label\' => \'Stores\',\'public\' => true,\'show_ui\' => true,\'_builtin\' => false, \'capability_type\' => \'post\',\'hierarchical\' => true,\'rewrite\' => array(\'slug\' => \'stores\'),\'query_var\' => true,\'supports\' => array(\'title\',\'editor\',\'excerpt\',\'trackbacks\',\'custom-fields\',\'comments\',\'revisions\',\'thumbnail\',\'author\',\'page-attributes\')) );
register_post_type($post_tax[\'state\'][\'post\'], array(\'label\' => \'States\',\'public\' => true,\'show_ui\' => true,\'_builtin\' => false, \'capability_type\' => \'post\',\'hierarchical\' => true,\'rewrite\' => array(\'slug\' => \'states\'),\'query_var\' => true,\'supports\' => array(\'title\',\'editor\',\'excerpt\',\'trackbacks\',\'custom-fields\',\'comments\',\'revisions\',\'thumbnail\',\'author\',\'page-attributes\')) );
}
Hook into the init action and call create_post_type_taxonomies when it fires
add\\u action(\'init\',\'create\\u beer\\u taxonomies\',0);
Create taxonomies for their corresponding post types
function create_beer_taxonomies()
{
global $post_tax;
// Add new taxonomy
$labels = array(
\'name\' => _x( \'Stores\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Store\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Stores\' ),
\'all_items\' => __( \'All Stores\' ),
\'parent_item\' => __( \'Parent Store\' ),
\'parent_item_colon\' => __( \'Parent Store:\' ),
\'edit_item\' => __( \'Edit Store\' ),
\'update_item\' => __( \'Update Store\' ),
\'add_new_item\' => __( \'Add New Store\' ),
\'new_item_name\' => __( \'New Store Name\' ),
);
// Make it hierarchical (like categories) and assign to specific post types
register_taxonomy($post_tax[\'store\'][\'tax\'],
array(\'post\',$post_tax[\'review\'][\'post\']),
array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'stores-bp\' ),
));
$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\' ),
);
register_taxonomy($post_tax[\'state\'][\'tax\'],
array(\'post\',$post_tax[\'beer\'][\'review\']),
array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'states-bp\' ),
));
}
In Template/Loopfunction meta_loop_beers($queried_tax,$queried_term){
//$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$queried_page = get_query_var(\'paged\');
$paged = $queried_page ? $queried_page : 1;
$post_type = \'\';
global $post_tax;
foreach($post_tax as $relation){
if( $relation[\'tax\'] == $queried_tax ){
$post_type = $relation[\'post\'];
break;
}
}
$args=array(
\'post_type\' => \'post\',
$queried_tax => $queried_term,
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'caller_get_posts\'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
<PUT LOOP(S) HERE>
wp_reset_query();
}
我相信这就是一切。您将无法复制粘贴该代码并使其自动为您工作,但它有望为您提供如何使其工作的想法。这是当时最前沿的东西,大约在6个月前完成,我猜在某些地方有更好的实现。不幸的是,该网站还没有直播,所以目前没有什么可显示的。
我们还必须重定向(htaccess)这些slug以用于分类法,因为我们希望那些查找存储(post-type)和存储存档(taxonomy)的slug落在存储的“配置文件页”同时显示两者的同一页面上。
因此,最终的结果是域的归档页面。com/stores bp/walmart将重定向到域。com/stores/walmart。
太令人困惑了!我可以试着在需要的地方澄清。