Making pages also serve as taxonomies? Or give full pages to taxonomies?

There are a few choices to go with this. I’ve actually gone through the same though process you have been. It would be easy if WordPress let you link posts or custom post types together but in lieu of that, the hackery of WordPress developers must occur!

The solution I went with in the plugin I’m working on is a bit hacky, but it works for me. Basically in my plugin, I wanted to have a post type called series that holds info on a particular tv series, a post type for episodes and another post type for DVD and Blu-ray releases. I wanted both the episode and releases post types to reference the series type they come from, so if I create a single series post page, it could list the episodes and releases as well as the series info.

My solution involves a custom field that holds the object id of the series. The first way to accomplish this was to create a metabox that had a select box of all the posts of type series:

public function get_select_array($post_type) {
    global $wpdb;
    $query = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type="$post_type" AND post_status="publish" ORDER BY post_title";
    $results = $wpdb->get_results($query, OBJECT);
    $series = array();
    foreach ($results as $result) {
        $series[] = array('name' => $result->post_title, 'value' => $result->ID);
    }
    return $series;                 
}

The function get_select_array() basically takes a custom post type and returns the post titles and ID’s of all the ones that are published in an array. I then use that array to populate a select box. In my plugin, I’m using the metabox creation class created by Rilwis but I’ll post some code for you to use (code is adapted from Rilwis’s code):

add_meta_box('parent_series', 'Series', 'show_series_metabox', 'episode', 'side', 'high');  //add a side metabox
function show_series_metabox() {
    global $post;
    echo '<input type="hidden" name="wp_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';  //nonce
    $series = get_select_array('series'); //get post titles and ID's of post type 'series
    $meta = get_post_meta($post->ID, 'parent_series', true); //get the meta value of the custom field
    echo '<select name="parent_series" id="parent_series">';//create the select box
    foreach ($series as $s) {
        echo '<option value="', $s['value'], '"', $meta == $s['value'] ? ' selected="selected"' : '', '>', $s['name'], '</option>';
    }
    echo '</select>';
}
add_action('save_post', 'save_series_metabox');
function save_series_metabox() {
    $real_post_id = isset($_POST['post_ID']) ? $_POST['post_ID'] : NULL ;   //get post id
    $old = get_post_meta($real_post_id, 'parent_series', true);             //get old stored meta value
    $new = $_POST['parent_series'];                                         //new meta value
    if ($new && $new != $old) {                                             //saving or deleting value
        update_post_meta($real_post_id, 'parent_series', $new);
    } elseif ('' == $new && $old) {
        delete_post_meta($real_post_id, 'parent_series', $old);
    }
}

This will add a metabox that has a select that lists all the series available. When the post is saved, the id of that series will be saved in a custom field called ‘parent_series’. Once that is done, you can call on that id and use it to call the series info via a custom query. Or its possible to do the opposite: on the series page, you do a query for all the episode pages that have the same value in their custom field/meta data.

And there you have it. Using this code you can link posts of one type to those of another, making them work like pseudo taxonomies in a way. I edited the code up pretty quickly so if you find any errors or bugs, let me know. If there are better ways to do this, please let me know 🙂

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)