我已经创建了一个自定义的帖子类型(公文包),并且正在使用内置的类别分类法。当我查看类别存档页面时,只有常规帖子显示在类别下,我的自定义帖子根本不存在。选择类别的选项在编辑帖子页面(和快速编辑)中,它们只是没有显示在前端。
我已尝试通过在“设置”下保存来刷新永久链接>;Permalinks,我也尝试过包括flush_rewrite_rules();
在我的功能中。php。什么都没用?
这是我的自定义帖子类型代码(注意:我的自定义帖子可以很好地使用重写规则,只是类别):
/**
* Registers the \'apc_portfolio\' custom post type.
*
* @example register_post_type( $taxonomy, $args );
* @see https://codex.wordpress.org/register_post_type#Parameters
* @todo change public, to false
*/
function apc_register_portfolio_post_type() {
$labels = array(
\'add_new_item\' => __( \'Add New Portfolio Item\', \'detail-factory-2020\' ),
\'add_new\' => __( \'Add New Portfolio\', \'detail-factory-2020\' ),
\'all_items\' => __( \'All Portfolio Items\', \'detail-factory-2020\' ),
\'archives\' => __( \'Portfolio Item Archives\', \'detail-factory-2020\' ),
\'attributes\' => __( \'Portfolio Item Attributes\', \'detail-factory-2020\' ),
\'edit_item\' => __( \'Edit Portfolio Item\', \'detail-factory-2020\' ),
\'featured_image\' => __( \'Featured Image\', \'detail-factory-2020\' ),
\'filter_items_list\' => __( \'Filter Portfolio Items list\', \'detail-factory-2020\' ),
\'insert_into_item\' => __( \'Insert into Portfolio Item\', \'detail-factory-2020\' ),
\'items_list_navigation\' => __( \'Portfolio Items list navigation\', \'detail-factory-2020\' ),
\'items_list\' => __( \'Portfolio Items list\', \'detail-factory-2020\' ),
\'menu_name\' => __( \'Portfolio\', \'detail-factory-2020\' ),
\'name_admin_bar\' => __( \'Portfolio Item\', \'detail-factory-2020\' ),
\'name\' => _x( \'Portfolio Items\', \'Post Type General Name\', \'detail-factory-2020\' ),
\'new_item\' => __( \'New Portfolio Item\', \'detail-factory-2020\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'detail-factory-2020\' ),
\'not_found\' => __( \'Not found\', \'detail-factory-2020\' ),
\'parent_item_colon\' => __( \'Parent Portfolio Item:\', \'detail-factory-2020\' ),
\'remove_featured_image\' => __( \'Remove featured image\', \'detail-factory-2020\' ),
\'search_items\' => __( \'Search Portfolio Item\', \'detail-factory-2020\' ),
\'set_featured_image\' => __( \'Set featured image\', \'detail-factory-2020\' ),
\'singular_name\' => _x( \'Portfolio Item\', \'Post Type Singular Name\', \'detail-factory-2020\' ),
\'update_item\' => __( \'Update Portfolio Item\', \'detail-factory-2020\' ),
\'uploaded_to_this_item\' => __( \'Uploaded to this Portfolio Item\', \'detail-factory-2020\' ),
\'use_featured_image\' => __( \'Use as featured image\', \'detail-factory-2020\' ),
\'view_item\' => __( \'View Portfolio Item\', \'detail-factory-2020\' ),
\'view_items\' => __( \'View Portfolio Items\', \'detail-factory-2020\' ),
);
$rewrite = array(
\'feeds\' => false,
\'pages\' => false,
\'slug\' => \'work\',
\'with_front\' => true,
);
$args = array(
\'can_export\' => true,
\'capability_type\' => \'post\',
\'exclude_from_search\' => false,
\'has_archive\' => true,
\'hierarchical\' => false,
\'label\' => __( \'Portfolio Item\', \'detail-factory-2020\' ),
\'labels\' => $labels,
\'menu_icon\' => \'dashicons-portfolio\',
\'menu_position\' => 5,
\'public\' => true,
\'publicly_queryable\' => true,
\'rewrite\' => $rewrite,
\'show_in_admin_bar\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_rest\' => true,
\'show_ui\' => true,
\'supports\' => array(
\'custom-fields\',
\'editor\',
\'excerpt\',
\'post-formats\',
\'thumbnail\',
\'title\',
),
\'taxonomies\' => array( \'category\' ),
);
register_post_type( \'apc-portfolio\', $args );
}
add_action( \'init\', \'apc_register_portfolio_post_type\', 0 );