如何在同一层次结构中拥有页面和自定义-post-类型

How to have a page and custom-post-type on same hierarchy

我正在寻找一种在 WordPress 的相同 url 层次结构中拥有“工作”和带有“申请表”的页面的方法。

职位 (CPT):

/jobs/engineer/
/jobs/ceo/

申请表页面(Page):

/jobs/application-form/

据我所知,在 WordPress 中不能混合“帖子”和“页面”。

也许我必须通过在作业中添加“/detail/”或其他内容来帮助自己。

感谢帮助!

In my understanding its not possible to mix "posts" and "pages" in WordPress.

没错,因为 post 不是分层的,但页面是。

当您使用 register_post_type() 注册自定义 post 类型时,您可以使用参数 hierarchical 将其设置为分层。默认值为 false。

如果您设置 'hierarchical' => true,您的自定义 post 类型将像 PAGE 一样工作,具有分层功能。如果您设置 'hierarchical' => false,您的自定义 POST 类型将像 post 一样,没有分层功能。

完成后,将自定义 post 类型设置为 jobs'hierarchical' => true 并创建一个名为 details 的父页面和一个名为 application-form 会得到你 /jobs/details/application-form/.

add_action( 'init', function() {
  $args = [
    // ...
    'hierarchical' => true,
    // ...
  ];
  register_post_type( '_your_custom_post_type_slug_', $args );
} );