自定义帖子类型的类别 URL

时间:2021-07-15 09:18:45

标签: wordpress custom-post-type

我有一个自定义帖子类型的下拉过滤器。代码如下所示:

<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

理想情况下,cat 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
    ));
}

默认帖子类型的相同设置效果很好。

如果有人能对此有所了解,我们将不胜感激。

0 个答案:

没有答案