WP分类法重写 - 基于Post Type名称的预端SLUG



是否可以根据当前正在查看的帖子类型动态预订分类法?

我目前有一个分类法,我正在重写slug,以便将分类法进行如下:

$labels = array(
    "name" => __( "Locations", "" ),
    "singular_name" => __( "Location", "" ),
);
$args = array(
    "label" => __( "Locations", "" ),
    "labels" => $labels,
    "public" => true,
    "hierarchical" => true,
    "label" => "Locations",
    "meta_box_cb" => false,
    "show_ui" => true,
    "show_in_menu" => true,
    "show_in_nav_menus" => true,
    "query_var" => true,
    "rewrite" => array( 'slug' => 'property-sales/location', 'with_front' => true,  'hierarchical' => true, ),
    "show_admin_column" => false,
    "show_in_rest" => false,
    "rest_base" => "",
    "show_in_quick_edit" => true,
);
register_taxonomy( "location", array( "property_sales" ), $args );

这可以正常工作,但是如果我还需要在property_rentals post type(property-rentals slug)上使用分类法和slug呢?谢谢!

从重写参数中删除 property-sales/

"rewrite" => array( 'slug' => 'location', 'with_front' => true,  'hierarchical' => true, ),

property_rentals添加到对象类型阵列中。

register_taxonomy( "location", array( "property_sales", "property_rentals" ), $args );

最新更新