自定义 Post 类型的 WordPress 永久链接结构

WordPress Permalink Structure for Custom Post Type

我正在构建一个站点,但不知道如何更改我的自定义 post 类型的固定链接结构!

我现在有一个名为“Products”的自定义 post 类型,它具有这样的 URL 结构

/products/continental-rack/

我的自定义 post 类型的完整代码如下:

function cpt_products() {
  $labels = array(
    'name'               => 'Products',
    'singular_name'      => 'Product',
    'menu_name'          => 'Products',
    'name_admin_bar'     => 'Product',
    'add_new'            => 'Add New',
    'add_new_item'       => 'Add New Product',
    'new_item'           => 'New Product',
    'edit_item'          => 'Edit Product',
    'view_item'          => 'View Product',
    'all_items'          => 'All Products',
    'search_items'       => 'Search Products',
    'parent_item_colon'  => 'Parent Product',
    'not_found'          => 'No Products Found',
    'not_found_in_trash' => 'No Products Found in Trash'
  );

  $args = array(
    'labels'              => $labels,
    'public'              => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'show_ui'             => true,
    'show_in_nav_menus'   => true,
    'show_in_menu'        => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'menu_icon'           => 'dashicons-tag',
    'capability_type'     => 'post',
    'taxonomies'          => array( 'category' ),
    'hierarchical'        => false,
    'supports'            => array( 'title', 'author', 'thumbnail' ),
    'has_archive'         => true,
    'rewrite'             => array( 'slug' => 'products' ),
    'query_var'           => true
  );

  register_post_type( 'products', $args );
}
add_action( 'init', 'cpt_products' );

我已经启用了右侧的类别部分,因此我可以select一个类别,但是当检查一个类别时,我不能将该类别显示在永久链接结构中。

所以我的目标永久链接结构基本上是这样的:

/%category-name%/products/continental-rack/

就是找不到办法。如有任何帮助,我们将不胜感激!

转到设置 -> 永久链接向下滚动到产品永久链接和 select 通用设置并将其添加到自定义结构 /%taxonomyname%/posttypename/

您可以添加过滤器 post_type_link

正确的方法是:https://wordpress.stackexchange.com/a/22490