Question

I'd like to create a custom post type and add this as a child post of some but not all existing standard posts (which are not pages). Is this possible?

Can I, for example, create a custom post type and then include this in other posts using a shortcode? Is there a better way to do this using custom taxonomies?

Was it helpful?

Solution

Is there a better way to do this using custom taxonomies?

You're right on the money there. Rather than try to make a custom post into the child of a standard post (because you can't), I'd recommend using a custom taxonomy to order things.

Essentially, you could build a custom hierarchical taxonomy and use it to "categorize" both standard posts and custom posts. You'd mark your standard posts as the parent in the taxonomy and your custom posts as the child.

A second option

Another option would be to use a custom field for parental inheritance. This might be a bit faster to code and more intuitive to use (plus it will give you some added control).

Add a custom meta field to your custom post type called "parents." This can then be a list of post IDs the child post should be nested under. When you need to call up the list, you can do a quick query to SELECT all of your custom posts that have the parent ID in question in their "parents" list.

OTHER TIPS

I think the Posts 2 Posts plugin does what you need to do. You will have to write some of the logic yourself, but it provides a nice API for many-to-many relationships between posts (of any type).

Can I, for example, create a custom post type and then include this in other posts using a shortcode? Is there a better way to do this using custom taxonomies?

<?php query_posts( array( 'post_type' => array('post', 'CUSTOM_POST_TYPE_HERE') ) ); ?>

Put this in the relevant template above if(have_posts()). This will allow both posts and your custom type to be shown.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top