Search code examples
wordpresscustom-post-type

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!


Solution

  • 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 );
    } );