wp如何设置自定义分类为默认分类

WP在注册custom taxonomy的时候添加default_term就好了。

function abt_register_taxonomy() {
//this code is 
  $args = array(
    'labels' => array(
      'name'  => 'Product Categories',
      'singular_name'  => 'Product Category',
      'all_items'  => 'All Categories',
      'edit_item'  => 'Edit Category',
      'view_item'  => 'View Category',
      'add_new_item'  => 'Add new category',

    ),
    'public'  => true,
    'show_in_rest'  => true,
    'hierarchical'  => true,
    'show_admin_column'  => true,
    'rewrite' => array(
      'slug'  => 'categories'
    ),
    'default_term'  => 'All'
  );
  register_taxonomy('product_category','products',$args);

然后在分类创建All的分类,下次发布的时候会自动选中

Share :