WP分类法重写 - 根据帖子类型名称预先设置slug

时间:2017-09-27 15:54:10

标签: wordpress

是否可以根据当前正在查看的帖子类型动态添加分类标本?

我目前有一个分类法,我正在重写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帖子类型(property-rentals slug)预先设置了slug,该怎么办?谢谢!

1 个答案:

答案 0 :(得分:1)

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

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

property_rentals添加到对象类型数组。

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