Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type called "Professions", it contains different professions and info about them. To show them I simply use a content-profession.php -file.

The thing is that I need subpages (childs) to those professions that contains info like salary, terms, where to find jobs, etc. They cannot be of the same type as the CPT Professions since that post type have a very specific layout. Is there any way to get a normal page as a child of a custom post type?

This was previously discussed here:

Page as child in custom post type slug?

but with the solution of rewriting URLs which feels like a very "hacky" solution to the problem.

share|improve this question
    
But addresses are handled by the rewrite API in WordPress. How should this work without changing rewrite rules? –  toscho Jul 9 '12 at 16:01
    
That's the question, is there any way to do it without URL rewrites. Perhaps being get the CPT inside the array of normal pages, set a mod to a page etc. Any suggestion is welcome –  Alm Jul 10 '12 at 8:27
    
why don't you add a custom field to your custom post type. with a dropdown of all your pages. So you just save the needed page as a custom field. Do what's necessary in your content page with this custom field? –  woony Jul 12 '12 at 14:49

3 Answers 3

You can link the "Professions" post type to pages (or any other post type) with a plugin called Sub Posts. It's not a free plugin, but it will do exactly what you're asking. More information can be found at www.subposts.com

share|improve this answer

When you register the post type you can set hierarchical to true.

hierarchical (boolean) (optional)

Whether the post type is hierarchical (e.g. page). Allows Parent to be specified. The 'supports' parameter should contain 'page-attributes' to show the parent select box on the editor page.

Default: false

Note: this parameter was planned for Pages. Be careful, when choosing it for your custom post type - if you are planning to have many entries (say - over 100), you will run into memory issue. With this parameter set to true WordPress will fetch all entries of that particular post type, together with all meta data, on each administration page load for your post type.

Then make sure the supports array includes page-attributes to show the parent menu.

eg:

// Register post type
register_post_type('your-post-type' , array(
    'labels' => $labels,
    'hierarchical' => true,
    'supports' => array( 'title', 'editor', 'page-attributes' )
) );

More info in the codex

share|improve this answer

The plugin mentioned by Barry seem pretty much what you need, but if you don't want to buy anything, here's another possible solution:

You could add a custom field in the subpages themselves holding the profession id.

Then in the profession page, you could do a post query with as argument the meta value to get all the pages that have this profession id as a custom field value. And like this generate your links...

The good think is that if you decide that some of these pages are repeated for every profession and have always same layout, you could turn them into there own custom post type, you would just need to include them in the query, but all the rest can work with the same logic...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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