未找到非固定链接自定义分类

时间:2015-04-25 作者:icc97

我在发布这篇文章时发现了这个问题,但我花了很长时间才找到大量“刷新永久链接”的答案。

<?php
add_action( \'init\', \'mytheme_create_post_type\' );
function mytheme_create_post_type() {  // jobs custom post type
    // set up labels
    $job_labels = array(
        \'name\' => __( \'Jobs\' ),
        \'singular_name\' => __( \'Job\' ),
        \'add_new\' => __( \'Add New\' ),
        \'add_new_item\' => __( \'Add New Job\' ),
        \'edit_item\' => __( \'Edit Job\' ),
        \'new_item\' => __( \'New Job\' ),
        \'all_items\' => __( \'All Jobs\' ),
        \'view_item\' => __( \'View Job\' ),
        \'search_items\' => __( \'Search Jobs\' ),
        \'not_found\' =>  __( \'No Jobs Found\' ),
        \'not_found_in_trash\' => __( \'No Jobs found in Trash\' ),
        \'parent_item\'       => __( \'Parent Job\' ),
        \'parent_item_colon\' => __( \'Parent Job:\' ),
        \'menu_name\' => __( \'Jobs\' ),
    );
    register_post_type(
        \'job\',
        array(
            \'labels\' => $job_labels,
            \'has_archive\' => true,
            \'public\' => true,
            \'hierarchical\' => false,
            \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'custom-fields\', \'thumbnail\', \'page-attributes\' ),
            \'taxonomies\' => array( \'post_tag\', \'job_category\' ),
            \'exclude_from_search\' => true,
            \'capability_type\' => \'post\'
        )
    );

    register_taxonomy_for_object_type( \'job_category\', \'job\' );
}

add_action( \'init\', \'mytheme_create_taxonomies\', 5 );
function mytheme_create_taxonomies() {
    // job taxonomy
    $job_labels = array(
        \'name\'              => _x( \'Job Categories\', \'taxonomy general name\' ),
        \'singular_name\'     => _x( \'Job Category\', \'taxonomy singular name\' ),
        \'search_items\'      => __( \'Search Job Categories\' ),
        \'all_items\'         => __( \'All Job Categories\' ),
        \'parent_item\'       => __( \'Parent Job Category\' ),
        \'parent_item_colon\' => __( \'Parent Job Category:\' ),
        \'edit_item\'         => __( \'Edit Job Category\' ),
        \'update_item\'       => __( \'Update Job Category\' ),
        \'add_new_item\'      => __( \'Add New Job Category\' ),
        \'new_item_name\'     => __( \'New Job Category\' ),
        \'menu_name\'         => __( \'Job Categories\' ),
    );
    register_taxonomy(
        \'job_category\',
        \'job\',
        array(
            \'hierarchical\' => false,
            \'labels\' => $job_labels,
            \'rewrite\' => false,
            \'show_admin_column\' => true
        )
    );
}
考虑到permalinks的问题,我把所有的东西都关掉了。我会将Settings>Permalinks设置为默认值并设置rewrite => false 对于post类型和分类法。

但是,在创建一个包含HR类别的工作后http://www.example.com/?job_category=hr 给了我一个“抱歉,没有找到结果”,即不是404,但该类别没有结果。

1 个回复
SO网友:icc97

问题是\'exclude_from_search\' => trueregister_post_type 选项。

考虑到该设置\'public\' => true 默认情况下,我假设这是正确的设置。

然而,这在WordPress codex中register_post_type exclude_from_search:

Note: 如果要显示与分类法术语相关联的帖子列表,必须将exclude\\u from\\u search设置为false(即:for call site\\u domaine/?taxonomy\\u slug=term\\u slug或site\\u domaine/taxonomy\\u slug/term\\u slug)。如果设置为true,WordPress将在分类页面(例如:taxonomy.php)上找不到您的帖子和/或分页将产生404错误。。。

结束

相关推荐