wordpress - 自定义帖子类型的类别 URL
问题描述
我有一个自定义帖子类型的下拉过滤器。代码如下所示:
<form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/resources/vat-gst-alerts/' ) ); ?>" method="get">
<?php $args = array(
child_of => 40,
hierarchical => 1,
show_count => 1,
show_option_all => 'All'
); ?>
<?php wp_dropdown_categories($args); ?>
<input type="submit" name="submit" value="FILTER" />
</form>
这会正确过滤并返回以下网址:
domainname.co.uk/resources/vat-gst-alerts/?cat=42&submit=FILTER
理想情况下,猫 id 是猫的名字,但它可以工作。
但是,当我使用该功能时:
<?php the_category(', '); ?>
在 content.php 模板上,它不起作用并显示消息。
我们似乎找不到您要查找的内容。也许搜索会有所帮助。
链接现在看起来像这样:
domainname.co.uk/category/vat-gst-alerts/another-test-category/
该链接在易于阅读方面对用户更友好,但只是不起作用,我不确定为什么?
functions.php 中 CPT 的代码如下所示:
add_action('init', 'register_mypost_type', 1);
function register_mypost_type() {
register_post_type('vatgst',array(
'labels' => array(
'name' => 'VAT/GST Alerts',
'singular_name' => 'VAT/GST Alert',
'add_new' => 'Add VAT/GST Alert',
'add_new_item' => 'Add VAT/GST Alert',
'edit_item' => 'Edit VAT/GST Alert',
'new_item' => 'Add New VAT/GST Alert',
'view_item' => 'View VAT/GST Alert',
'search_items' => 'Search VAT/GST Alerts',
'not_found' => 'No VAT/GST alerts found',
'not_found_in_trash' => 'No VAT/GST alerts found in trash'
),
'public' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt'),
'capability_type' => 'post',
'rewrite' => array('slug' => 'resources/vat-gst-alerts','with_front' => true,),
'taxonomies' => array('category'),
'menu_position' => 7,
'has_archive' => true,
'hierarchical' => true
));
}
默认帖子类型的相同设置效果很好。
如果有人能对此有所了解,将不胜感激。
解决方案
推荐阅读
- ios - RxSwift 和三个 API 请求
- maven - 用于查找工件的 Nexus 存储库管理器不起作用
- java - 将多个 byte[] 放入单个响应体
- wordpress - 如何创建可重用的 CircleCI 松弛 ORB
- javascript - 基于“data-”属性的 JQuery 对 div 进行排序
- cron - Azure Functions with NCrontab 返回方法未找到消息
- php - MVC 模板变量,我是否超出了范围?
- powerbuilder - PowerBuilder 中的 DLL 劫持
- elf - objcopy:臃肿的二进制输出文件
- mongodb - 即使我在使用 Typeorm 创建的实体中将数据创建为“可空:假”,我也可以将其保存为“空”