Make one post-type the taxonomy of another post-type

Howdy! :sunglasses:
I'm trying to set-up a plant database with custompress - pretty similar to the one you describe on the usage-tab of the plugin-page - but with two instances. So instead of just one post-type ("plants"), I want it to also have a second post-type for the different "varieties". Also "plants" should be the taxonomy for "varieties" or the parent element.
Any ideas? Is it even possible?

Thank's for the help!

  • Swapnil

    Hello Peter Schemm,

    That's a great question. What you are trying to achieve is called 'Linking terms'. Where the taxonomy of one post type is another post type. Developers don't need such kind of structure very often, considering the complexity it brings it.

    But hey, that should not discourage you. It is absolutely possible. It's just that you may not be able to achieve that completely with CustomPress, only. A better idea is to make the post types and taxonomies using CustomPress so you don't have to code it yourself, saves a lot of time :stuck_out_tongue: Then Export them, and then linking the taxonomies to the post types according to your need.

    This will involve custom code, it shouldn't be too difficult to do. Here is an article that explains it in detail http://justintadlock.com/archives/2010/08/20/linking-terms-to-a-specific-post
    You will only need to follow steps for linking the post type as taxonomy. CustomPress already does link a taxonomy to the post type for you.

    Hope that helps,

    Cheers,
    Swapnil V. Patil

  • euDigital

    Hit here mate , sounds like you need a custom taxonomy for your post type
    Here is a good piece of writing on that . It's no that hard , just open your functions.phpmfrom your the and chuck in there A bit of code .

    Ave a look at this link :
    https://wordpress.stackexchange.com/questions/57493/custom-taxonomy-specific-to-a-custom-post-type

    So first you have your function tomregister your taxonomy.

    function themes_taxonomy() {
    register_taxonomy(
    'themes_categories', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    'themes', //post type name
    array(
    'hierarchical' => true,
    'label' => 'Themes store', //Display name
    'query_var' => true,
    'rewrite' => array(
    'slug' => 'themes', // This controls the base slug that will display before each term
    'with_front' => false // Don't display the category base before
    )
    )
    );
    }
    add_action( 'init', 'themes_taxonomy');

    Basically wha is happening here instou are declaring the function that registers the taxonomy and then you that last line add_action younger running the function.

    Change the label and the slug to something that make sense to you and yournporjectb, register as many taxonomies you want there , if you want something like categories set the hierarchical value to true or if you want something that behaves more like a tag set the hierarchical value to false.

    Then you just need to link it to your post type of choice withe the other bit o code in the link to make it work and of course change the values that need changing. You could also take the uma and register yournpost type via functions instead of using a plugin to declare it while you are at it . :

    function filter_post_type_link($link, $post)
    {
    if ($post->post_type != 'themes')
    return $link;

    if ($cats = get_the_terms($post->ID, 'themes_categories'))
    $link = str_replace('%themes_categories%', array_pop($cats)->slug, $link);
    return $link;
    }
    add_filter('post_type_link', 'filter_post_type_link', 10, 2);

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.