我在网站上为特定操作定义了自定义帖子类型功能。以实现特定类型的url结构。我从中删除了持续的slug,并将其替换为类别和品牌名称。
上一个url为
www.website。com/产品/名称
新url为
www.website。商品/类别/品牌/名称
你看,我已经把鼻涕虫完全去掉了。这是代码。现在的问题是,这些URL不起作用,我得到一个404页作为回报。我也尝试过冲洗永久墨水,但没有效果。
根据我的理解,由于删除了slug,查询正在“Post”中搜索,而不是“Custom Post Type”,但我不知道如何更正它。我们将非常感谢您的回复。
// Register our Custom Post type as aps-products
public static function register_cpt_aps_products() {
$permalinks = get_aps_settings(\'permalinks\');
$slug = (isset($permalinks[\'product-slug\'])) ? $permalinks[\'product-slug\'] : \'\';
// labels text for our post type aps-products
$labels = array(
// post type general name
\'name\' => __( \'APS Products\', \'aps-text\' ),
// post type singular name
\'singular_name\' => __( \'APS Product\', \'aps-text\' ),
\'name_admin_bar\' => __( \'APS Product\', \'aps-text\' ),
\'menu_name\' => __( \'APS Products\', \'aps-text\' ),
\'add_new\' => __( \'Add New APS Product\', \'aps-text\' ),
\'add_new_item\' => __( \'Add New APS Product\', \'aps-text\' ),
\'edit_item\' => __( \'Edit APS Product\', \'aps-text\' ),
\'new_item\' => __( \'New APS Product\', \'aps-text\' ),
\'view_item\' => __( \'View APS Product\', \'aps-text\' ),
\'archives\' => __( \'APS Products Archives\', \'aps-text\' ),
\'search_items\' => __( \'Search APS Products\', \'aps-text\' ),
\'insert_into_item\' => __( \'Insert into APS Product\', \'aps-text\' ),
\'featured_image\' => __( \'APS Product Image\', \'aps-text\' ),
\'set_featured_image\' => __( \'Set APS Product Image\', \'aps-text\' ),
\'remove_featured_image\' => __( \'Remove APS Product Image\', \'aps-text\' ),
\'use_featured_image\' => __( \'Use as APS Product image\', \'aps-text\' ),
\'not_found\' => __( \'No APS Products found\', \'aps-text\' ),
\'not_found_in_trash\' => __( \'No APS Products found in Trash\', \'aps-text\' )
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'publicly_queryable\' => true,
\'show_in_nav_menus\' => false,
\'menu_icon\' => \'dashicons-products\',
\'capability_type\' => \'aps-products\',
\'capabilities\' => array(
\'read_post\' => \'read_aps_product\',
\'edit_post\' => \'edit_aps_product\',
\'edit_posts\' => \'edit_aps_products\',
\'delete_posts\' => \'delete_aps_products\',
\'create_posts\' => \'create_aps_products\',
\'publish_posts\' => \'publish_aps_products\',
\'edit_published_posts\' => \'edit_published_aps_products\',
\'delete_published_posts\' => \'delete_published_aps_products\',
\'edit_others_posts\' => \'edit_others_aps_products\',
\'delete_others_posts\' => \'delete_others_aps_products\',
\'read_private_posts\' => \'read_private_aps_products\',
\'edit_private_posts\' => \'edit_private_aps_products\',
\'delete_private_posts\' => \'delete_private_aps_products\'
),
\'map_meta_cap\' => true,
\'hierarchical\' => true,
\'taxonomies\' => array(\'post_tag\',\'aps-cats\', \'aps-brands\', \'aps-attributes\', \'aps-filters\', \'aps-rating-bars\'),
\'has_archive\' => true,
\'show_in_menu\' => \'aps-products\',
\'supports\' => array( \'publicize\',\'title\', \'editor\', \'thumbnail\', \'comments\', \'author\', \'excerpt\' ),
\'register_meta_box_cb\' => array(__CLASS__, \'add_aps_products_metabox\'),
\'rewrite\' => array(\'slug\' => \'/%aps-cats%/%aps-brands%/\', \'with_front\' => false)
);