I have a front-end posting form configured for a custom post type. By using the form I am able to send the title, content, and image attachments without a hitch, but my custom taxonomy selection doesn't register. I've patched this functionality using various bits of code I have found and I'm not sure exactly what I screwed up.
add-new-listing.php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") {
// Do some minor form validation to make sure there is content
if (isset ($_POST['title'])) {
$title = $_POST['title'];
} else {
echo 'Please enter the listing name';
}
if (isset ($_POST['description'])) {
$description = $_POST['description'];
} else {
echo 'Please enter a description';
}
$tags = $_POST['post_tags'];
// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title' => $title,
'post_content' => $description,
'post_category' => array($_POST['booru_locations']), // Usable for custom taxonomies too
'post_image' => $newupload,
'post_status' => 'publish', // Choose: publish, preview, future, draft, etc.
'post_type' => 'booru_directory' //'post',page' or use a custom post type if you want to
);
//SAVE THE POST
$pid = wp_insert_post($new_post);
//REDIRECT TO THE NEW POST ON SAVE
$link = get_permalink( $pid );
wp_redirect( $link );
//INSERT OUR MEDIA ATTACHMENTS
if ($_FILES) {
foreach ($_FILES as $file => $array) {
$newupload = insert_attachment($file,$pid);
// $newupload returns the attachment id of the file that
// was just uploaded. Do whatever you want with that now.
}
} // END THE IF STATEMENT FOR FILES
} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM
//POST THE POST YO
do_action('wp_insert_post', 'wp_insert_post');
functions.php
$labels = array(
'name' => 'Locations',
'singular_name' => 'Location',
'search_items' => 'Search Locations',
'popular_items' => 'Popular Locations',
'all_items' => 'All Locations',
'parent_item' => 'Parent Location',
'edit_item' => 'Edit Location',
'update_item' => 'Update Location',
'add_new_item' => 'Add New Location',
'new_item_name' => 'New Location',
'separate_items_with_commas' => 'Separate Locations with commas',
'add_or_remove_items' => 'Add or remove Location',
'choose_from_most_used' => 'Choose from most used Locations'
);
$args = array(
'label' => 'Locations',
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'place', 'with_front' => false ),
'query_var' => true
);
register_taxonomy( 'booru_locations', 'booru_directory', $args );
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Services', 'Service Type' ),
'singular_name' => _x( 'Service', 'Service' ),
'search_items' => __( 'Search Services' ),
'popular_items' => __( 'Popular Services' ),
'all_items' => __( 'All Services' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Services' ),
'update_item' => __( 'Update Service' ),
'add_new_item' => __( 'Add New Service' ),
'new_item_name' => __( 'New Service' ),
'separate_items_with_commas' => __( 'Separate Services With Commas' ),
'add_or_remove_items' => __( 'Add or Remove Services' ),
'choose_from_most_used' => __( 'Choose From Most Used Services' )
);
register_taxonomy( 'services', 'booru_directory', array(
'hierarchical' => false,
'labels' => $labels, /* NOTICE: the $labels variable here */
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'services' ),
));
register_post_type( 'booru_directory',
array(
'labels' => array(
'name' => __( 'Directory' ),
'singular_name' => __( 'Listing' )
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'rewrite' => array( 'slug' => 'directory', 'with_front' => false ),
'has_archive' => true
)
);
$_POST['booru_locations']a category id, or is a category name? – m0r7if3r Mar 7 '12 at 20:15