我四处看看,但找不到像样的解决办法。
我有一个自定义的帖子类型,可以添加业务。在循环中,默认情况下它将列出所有内容,但我希望能够将事件类别附加到每个自定义帖子,以便我可以根据该事件在单独的页面上进行筛选。
基本上每个自定义帖子都会分配一个类别。因此,活动“PartyOne”将有自定义帖子,其中包含详细信息、常见问题解答和赞助商列表。
我有针对赞助商列表和常见问题的自定义帖子,但有没有办法将它们全部分组?那么,当他们点击PartyOne页面时,它会链接常见问题解答、赞助商和该活动的帖子内容?
我想注册自定义帖子类型,然后将url与类别分配为mysite。com/partyone/exhibing/businessname,但当我发表自定义帖子时,它只写我的网站。com/exhibing/businessname在这里,我需要“partyone”作为一只猫来将它们捆绑在一起,这就是我目前所拥有的
// Register custom taxonomy before post type
function add_event_taxonomies() {
register_taxonomy(\'event\', \'exhibitors\', array(
// Hierarchical taxonomy (like categories)
\'hierarchical\' => true,
// This array of options controls the labels displayed in the WordPress Admin UI
\'labels\' => array(
\'name\' => _x( \'Exhibitor Category\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Exhibitor-Category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Exhibitor-Categories\' ),
\'all_items\' => __( \'All Exhibitor-Categories\' ),
\'parent_item\' => __( \'Parent Exhibitor-Category\' ),
\'parent_item_colon\' => __( \'Parent Exhibitor-Category:\' ),
\'edit_item\' => __( \'Edit Exhibitor-Category\' ),
\'update_item\' => __( \'Update Exhibitor-Category\' ),
\'add_new_item\' => __( \'Add New Exhibitor-Category\' ),
\'new_item_name\' => __( \'New Exhibitor-Category Name\' ),
\'menu_name\' => __( \'Exhibitor Categories\' ),
),
// Control the slugs used for this taxonomy
\'rewrite\' => array(
\'slug\' => \'exhibitors/%category%\', // This controls the base slug that will display before each term
\'with_front\' => false, // Don\'t display the category base before "/locations/"
\'hierarchical\' => true // This will allow URL\'s like "/locations/boston/cambridge/"
),
));
}
add_action( \'init\', \'add_event_taxonomies\', 0 );
// Register Exhibitors Post Type
function exhibitors_init() {
$args = array(
\'label\' => \'Exhibitors\',
\'public\' => true,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'rewrite\' => array(\'slug\' => \'exhibitors\'),
\'query_var\' => true,
\'menu_icon\' => \'dashicons-megaphone\',
\'supports\' => array(
\'title\',
\'editor\',
\'custom-fields\',
\'revisions\',
\'thumbnail\',
\'page-attributes\'),
);
register_post_type( \'exhibitors\', $args );
}
add_action( \'init\', \'exhibitors_init\' );
因此,它为参展商注册了一个自定义类别,但当我创建一个新帖子时,它不会将该类别附加到永久链接。有什么想法吗?此外,如果有更好的解决方案,我愿意从头开始