终于找到了答案。这是我在网上找到的多种不同解决方案的组合,但它就在这里!
第一步是将其添加到函数中。php
add_rewrite_rule(
\'products/([^/]+)/([^/]+)/?\',
\'index.php?pmfg_product_categories=$matches[1]&products=$matches[2]\',
\'top\'
);
其次,你需要在你的网站上使用它。配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules><rule name="WordPress Rule" stopProcessing="true"><match url=".*"/><conditions><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/></conditions><action type="Rewrite" url="index.php?page_id={R:0}"/></rule>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
</rewrite>
</system.webServer>
</configuration>
最后,这里是我如何有我的自定义帖子类型和分类设置。将“yourid”替换为您想要的任何内容,以确保您与其他插件没有任何问题。
// Register Custom Post Type
function yourid_product_tax_type(){
$labels = array(
\'name\' => _x( \'Product Categories\', \'Taxonomy General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Product Category\', \'Taxonomy Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Product Categories\', \'text_domain\' ),
\'all_items\' => __( \'All Product Categories\', \'text_domain\' ),
\'parent_item\' => __( \'Parent Category\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Category:\', \'text_domain\' ),
\'new_item_name\' => __( \'New Product Category Name\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Product Category\', \'text_domain\' ),
\'edit_item\' => __( \'Edit Product Category\', \'text_domain\' ),
\'update_item\' => __( \'Update Product Category\', \'text_domain\' ),
\'separate_items_with_commas\' => __( \'Separate categories with commas\', \'text_domain\' ),
\'search_items\' => __( \'Search Product Categories\', \'text_domain\' ),
\'add_or_remove_items\' => __( \'Add or remove product categories\', \'text_domain\' ),
\'choose_from_most_used\' => __( \'Choose from the most used product categories\', \'text_domain\' ),
\'not_found\' => __( \'Product Category Not Found\', \'text_domain\' ),
);
$args = array(
\'label\' => \'Product Categories\',
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'args\' => array( \'orderby\' => \'term_order\' ),
\'rewrite\' => array(
\'slug\' => \'test\',
\'with_front\'=>true,
),
\'query_var\' => true,
);
register_taxonomy( \'yourid_product_categories\', array(), $args );
}
add_action( \'init\', \'yourid_product_tax_type\', 0 );
function yourid_post_type() {
$labels = array(
\'name\' => _x( \'Products\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Product\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Products\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Product: \', \'text_domain\' ),
\'all_items\' => __( \'All Products\', \'text_domain\' ),
\'view_item\' => __( \'View Product\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Product\', \'text_domain\' ),
\'add_new\' => __( \'Add New\', \'text_domain\' ),
\'edit_item\' => __( \'Edit Product\', \'text_domain\' ),
\'update_item\' => __( \'Update Product\', \'text_domain\' ),
\'search_items\' => __( \'Search Product\', \'text_domain\' ),
\'not_found\' => __( \'Product Not Found\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'Product not found in Trash\', \'text_domain\' ),
);
$rewrite = array(
\'slug\' => \'products\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => true,
);
$args = array(
\'label\' => __( \'yourid_product\', \'text_domain\' ),
\'description\' => __( \'YourName Products\', \'text_domain\' ),
\'labels\' => $labels,
\'taxonomies\' => array( \'yourid_product_categories\' ),
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => array(
\'slug\'=>\'products\',
\'with_front\'=>false,
),
\'capability_type\' => \'page\',
);
register_post_type( \'yourid_product\', $args );
}
// Hook into the \'init\' action
add_action( \'init\', \'yourid_post_type\', 0 );
如果您有任何问题或需要帮助,请告诉我!