Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

I am searching for a way to have "jobs" and a page with an "application form" in the same url-hierarchy in WordPress.

The jobs (CPT):

/jobs/engineer/
/jobs/ceo/

The application-form page (Page):

/jobs/application-form/

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

Maybe I have to help myself by adding "/detail/" or something else to the jobs.

Thanks for help!

question from:https://stackoverflow.com/questions/65848731/how-to-have-a-page-and-custom-post-type-on-same-hierarchy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

That's right, because post aren't hierarchical, but pages are.

When you register your custom post type using register_post_type() you can set it as hierarchical using the arguments hierarchical. The default value being false.

If you set 'hierarchical' => true your custom post type will act like a PAGE, with hierarchical capabilities. If you set 'hierarchical' => false your custom POST type will act like a post, without hierarchical capabilities.

Once this is done, after setting a custom post type as jobs with 'hierarchical' => true and creating a parent page called details and a child page called application-form will get you /jobs/details/application-form/.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...