自定义 WordPress 永久链接结构未针对所有自定义 post 类型更改

custom WordPress permalink structure not changed for all custom post types

我将我的 WordPress 站点中的默认永久链接结构更改为:www.example.com/blog/%postname%/。我希望“/blog/”部分仅适用于 posts。我有自定义 post 类型,例如 'education'、'case-study' 和 'resource',但我不希望 'blog' 成为 url 的一部分。我向 register_post_type 函数添加了一个重写参数,如下所示:'rewrite' => array('slug' => $slug , 'with_front' => false)。它适用于除 'resource' 之外的所有自定义 post 类型。我添加了代码来刷新重写规则,并且我重置了永久链接但没有成功。有什么我想念的吗?

解决方案(更新): 这是我注册自定义 post 类型的代码:

/** Remove extraneous resource custom post type */
add_action('init','delete_post_type', 5);
function delete_post_type(){
  unregister_post_type( 'resource' );
}

/** Register custom post types */
add_action( 'init', 'add_custom_register_post_types', 99 );
function add_custom_register_post_types() {    
  custom_register_post_type( 'Resource', 'Resources', 'resource', 'resources', true, array( 'title', 'editor', 'thumbnail' ), true, array( 'category' ) );
  custom_register_post_type( 'Case Study', 'Case Studies', 'case_study', 'case-studies', true, array( 'title', 'editor', 'thumbnail', ), true, array( 'category', 'post_tag' ) );
  custom_register_post_type( 'Product', 'Products', 'product', 'product', true, array( 'title', 'thumbnail' ), true, array(), false );
  custom_register_post_type( 'Guest Speaker', 'Guest Speakers', 'guest-speaker', 'guest-speaker', false, array( 'title', 'editor', 'thumbnail' ), true, array(), false );
  custom_register_post_type( 'News and Media Post', 'News and Media', 'news-and-media', 'company/news-and-media', true, array( 'title', 'editor' ), true, array() );
  custom_register_post_type( 'Education', 'Education', 'education', 'education1', true, array( 'title', 'editor', 'thumbnail', 'custom-fields' ), true, array( 'category', 'post_tag' ) );

  //flush_rewrite_rules();
}

function custom_register_post_type( $type, $types, $cpt_name, $slug, $search=false, $supports, $showui=true, $taxonomies, $has_archive = true ){

  $type2=strtolower( $type );
  $types2=strtolower( $types );

  $labels = array(
    'name' => $type,
    'singular_name' => $type,
    'add_new' => 'Add New',
    'add_new_item' => 'Add New ' .$type,
    'edit_item' => 'Edit '.$type,
    'new_item' => 'New '.$type,
    'view_item' => 'View '.$type,
    'search_items' => 'Search '.$types,
    'not_found' =>  'No '.$types2.' found',
    'not_found_in_trash' => 'No '.$types2.' found in Trash',
    'parent_item_colon' => '',
    'menu_name' => $types
  );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => $showui,
        'query_var' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'has_archive' => $has_archive,
        'rewrite' => array('slug' => $slug , 'with_front' => false),
        'exclude_from_search' => ! $search,
        'supports' => $supports,
        'taxonomies' => $taxonomies
    );

  register_post_type( $cpt_name, $args );
}

我无法弄清楚资源自定义 post 类型的其他地方在哪里被注册,但我发现了一个 hack 解决了我的问题。我添加了一个取消注册功能并将操作优先级设置为高于注册功能。我更新了我的代码以反映解决方案。我知道这不是最佳做法,但我不想永远花时间试图找出代码中其他地方的资源自定义 post 类型正在创建的位置。