16

I've seen a lot of posts out there in the Webiverse about assigning a page as a parent of a custom post type. After four hours I can't find a solution and need some help. I've create an "About" page that is the parent of an "Our People" page. I've also create a custom post type called "People". And I've created a custom page template for the "Our People" page. The Permalink structure looks fine until you get to the single "people" page. For Example: John Smith's Page, the permalink isn't correct.

Custom post type:

Desired Permalink Structure: /about-us/our-people/john-smith

Actually Permalink Structure: /our-people/john-smith

Our People Page Strucure: /about-us/our-people

The "about-us" is a page, "our-people" is a page and also the slug rewrite for the custom post type, "people". I've tried to change the hierarchical settings and I've tried adding "about-us/our-people" directly into the rewrite with no success.

Functions.php:

function codex_custom_init() {
    // Our People
    $people_label = array(
        'name' => 'People',
        'singular_name' => 'People',
        'add_new' => 'Add People',
        'add_new_item' => 'Add New People',
        'edit_item' => 'Edit People',
        'new_item' => 'New People',
        'all_items' => 'All People',
        'view_item' => 'View People',
        'search_items' => 'Search People',
        'not_found' => 'No People found',
        'not_found_in_trash' => 'No People found in Trash',
        'parent_item_colon' => '',
        'menu_name' => 'People',
    );
    $people_args = array (
        'labels' => $people_label,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'our-people'),
        'capability_type' => 'page',
        'has_archive' => true,
        'hierarchical' => true,
        'menu_position' => null,
        'menu_icon' => get_template_directory_uri() . '/images/icons/people.png',
        'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt','page-attributes'),
    );

    register_post_type('people', $people_args);
}

My Custom Templates: people.php people-single.php

19

This should work:

'rewrite' => array( 'slug' => 'about-us/our-people'),

combined with:

'has_archive' => false,

Make sure to visit the Permalinks settings page in your admin after you made the changes to flush the rewrite rules.

  • 2
    what will that do? – Nick Jan 15 '13 at 22:01
  • 7
    Would be great to see some explanations of why this would work. – montrealist Jan 22 '13 at 18:58
  • 3
    For anyone just trying to give their CPT a parent page, and not disable the archives, it's worth noting that 'has_archive' can also be passed a string for the archive slug. – jwinn Sep 9 '16 at 3:41
  • 3
    It's also worth noting that this won't inject 'about-us' into the Breadcrumbs from plugins such as Yoast. – Mir Nov 8 '18 at 22:23
  • 2
    @Mir any known workaround for that Yoast issue? – arvil Dec 12 '18 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.