0
votes

I have the following scenario.

I have custom post type 'project' with necessary custom taxonomy and custom tags under it. Now the requirement is every 'project' data has its own different pages( with acf same as that of default page ) as menu in detail page.

So I am thinking of adding another custom post type as 'project page' under post type 'project' and treat it as default page of WordPress. Is this possible ? I tried searching for custom post type under another post type but to no avail. How am I to approach this issue so the permalink of page also has project slug in it.

Any help/suggestions are welcome.

2
In your mind, why can't you use your current project custom post type, try to be a bit more clear than what you have written. Because from what you said, if you don't want your user to see the custom taxonomy you could just easily made them readonly to the admin. And with a custom post type in any case each project could have its own project page. I'm unclear in regards to what is the issue hereamarinediary
Any "post" from a custom post type as by default the custom post type slug in front of it in the permalink. in your case your default url to view a post from the custom post type project should be something like domain.com/project/my-awesome-new-project/amarinediary
If this is not the case, then you might have change the default Wordpress permalink structure. You should be able to reset it from the settings menu in the cpanel.amarinediary
If you really want second custom post type acting as "child" you can rewrite the permalink using the rewrite parameter upon cpt registration. 'rewrite' => [ 'slug' => 'project/project-page', ]should do the trick.amarinediary
@amarinediary sorry if I am not clear above. I have no problem in url or detail page of custom post type 'project'. It's fine. What I want is in project detail page say 'ABC' I want page as 'About Us','Contact Us' which should be like default wp page. The url for 'About Us' should be domain.com/project/abc/about-us. Hope you understand now.samjhana joshi

2 Answers

0
votes

You could make the 'project' post-type hierarchical.
Then use the parent relationship on the child page.

register_post_type('project', array(
    'hierarchical' => true,
    'supports' => array('page-attributes'), // show the parent select box on the editor page
    ... // Your other settings here
))

I'm not sure, if the parent-child relationship requires the two posts to be of the same post-type. Maybe you could try two different types.

This solution at least has the nested URL, you wanted to get. I'm not sure about integration with ACF, since the children are of the same post-type.

EDIT: Since you mentioned ACF, you could use the Relationship field type.

0
votes

Found the answer to whether you can add custom post type under another custom post type. It's possible. Just need to add the following code when registering custom post type.

'show_in_menu' => 'edit.php?post_type=project',

Regarding the project page permalink to include project slug I created it manually from the front(without view and permalink access in the admin part). In admin part I made acf 'Post Object' to relate the page to project. To show the detail page of project page I did the following.

add_action( 'init', function() {
    $url_path   = trim( parse_url( add_query_arg( array() ), PHP_URL_PATH ), '/' );
    $count      = count( explode( '/', $url_path ) );
    $slug       = end( explode( '/', $url_path ) );
    $postdetail = get_page_by_path( $slug, OBJECT, 'project_page' );
    if ( isset( $postdetail ) && ! empty( $postdetail ) ) {
        set_query_var( 'breadcrumb_id', $postdetail->ID );
        $params = array(
            'current_id' => $postdetail->ID,
        );
        $load = locate_template( 'templates/single/project_page.php', true, true, $params );
        if ( $load )
            exit();
    } else {
        return;
    }
});

This solved my problem as of now. Still looking for the best options.