so glad to know about the missing "{".
This whole thing is bringing to light my confusion between CPTs (custom post types) and taxonomy. I've been considering them as inseparable. Am I correct?
This is my aim: I have a 2 main categories: Video and Magazine. Furthermore, Videos are either Fiction or Non-Fiction; and Magazines are either Comedy or Drama.
Should my code attempt the following: create a CPT for Movies w/ a taxonomy for Comedy and a tax. for Drama? And in addition, create a CPT for Videos, w/ a tax. for Fiction and a tax. for Non-Fiction?
Let's say the answer is "yes". How do I code that?
Thanks for your patience!!!!
Here is my stab at that code, but it breaks.
/* create custom posts
*** vids
*/
add_action('init', 'create_vids');
function create_vids()
{
$labels = array(
'name' => __( 'Vids' ),
'singular_name' => __( 'Vids' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Mag' ),
'edit' => __( 'Edit' ),
'edit_item' => __( 'Edit Mag' ),
'new_item' => __( 'New Mag' ),
'view' => __( 'View Mag' ),
'view_item' => __( 'View Mag' ),
'search_items' => __( 'Search Vids' ),
'not_found' => __( 'No Vid Entries found' ),
'not_found_in_trash' => __( 'No Vid Entries found in Trash' ),
'parent' => __( 'Parent Vid' )
);
register_post_type(
'vid',
array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array("slug" => "vids"),
'supports' => array('title', 'editor', 'thumbnail')
)
);
}
/* create custom posts
*** mags
*/
add_action('init', 'create_mags');
function create_mags()
{
$labels = array(
'name' => __( 'Mags' ),
'singular_name' => __( 'Mags' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Mag' ),
'edit' => __( 'Edit' ),
'edit_item' => __( 'Edit Mag' ),
'new_item' => __( 'New Mag' ),
'view' => __( 'View Mag' ),
'view_item' => __( 'View Mag' ),
'search_items' => __( 'Search Mags' ),
'not_found' => __( 'No Mag Entries found' ),
'not_found_in_trash' => __( 'No Mag Entries found in Trash' ),
'parent' => __( 'Parent Mag' )
);
register_post_type(
'mag',
array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array("slug" => "mags"),
'supports' => array('title', 'editor', 'thumbnail')
)
);
}
/* create custom taxonomy
Vid
*/
add_action('init', 'build_taxonomy', 0);
function build_taxonomy()
{
// begin Vid
$labels = array(
'name' => _x( 'Vid Types', 'taxonomy general name' ),
'singular_name' => _x( 'Vid Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Vid Types' ),
'all_items' => __( 'All Vid Types' ),
'parent_item' => __( 'Parent Vid Type' ),
'parent_item_colon' => __( 'Parent Vid Type:' ),
'edit_item' => __( 'Edit Vid Type' ),
'update_item' => __( 'Update Vid Type' ),
'add_new_item' => __( 'Add New Vid Type' ),
'new_item_name' => __( 'New Vid Type' ),
);
register_taxonomy(
'type',
'vid',
array(
'hierarchical' => true,
'labels' => $labels,
'query_var' => true,
'rewrite' => true
)
);
}
/* create custom taxonomy
Mag
*/
add_action('init', 'build_taxonomy', 0);
function build_taxonomy()
{
// begin Mag
$labels = array(
'name' => _x( 'Mag Types', 'taxonomy general name' ),
'singular_name' => _x( 'Mag Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Mag Types' ),
'all_items' => __( 'All Mag Types' ),
'parent_item' => __( 'Parent Mag Type' ),
'parent_item_colon' => __( 'Parent Mag Type:' ),
'edit_item' => __( 'Edit Mag Type' ),
'update_item' => __( 'Update Mag Type' ),
'add_new_item' => __( 'Add New Mag Type' ),
'new_item_name' => __( 'New Mag Type' ),
);
register_taxonomy(
'type',
'mag',
array(
'hierarchical' => true,
'labels' => $labels,
'query_var' => true,
'rewrite' => true
)
);
}
/* custom columns */
add_filter("manage_edit-video_columns", "edit_columns" );
add_action("manage_posts_custom_column", "custom_columns");
function edit_columns($columns)
{
$columns = array(
"cb" => "<input type ='checkbox' />",
"title" => "Video Title",
"description" => "Description",
"price" => "Length",
"type" => "Video Type"
);
return $columns;
}
function custom_columns($column)
{
global $post;
switch ($column)
{
case "description":
the_excerpt();
break;
case "length":
$custom = get_post_custom($post->ID);
echo $custom['length'][0];
break;
case "type":
echo get_the_term_list($post->ID, 'type', '', ', ', '');
break;
}
}