Don't set/get tags or categories for post types that do not support them. fixes #13346

git-svn-id: http://svn.automattic.com/wordpress/trunk@14561 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-05-11 16:28:00 +00:00
parent 02058305b5
commit c7f520240c
1 changed files with 18 additions and 10 deletions

View File

@ -1992,13 +1992,20 @@ function wp_get_single_post($postid = 0, $mode = OBJECT) {
$post = get_post($postid, $mode); $post = get_post($postid, $mode);
// Set categories and tags // Set categories and tags
if($mode == OBJECT) { if ( $mode == OBJECT ) {
$post->post_category = wp_get_post_categories($postid); $post->post_category = array();
$post->tags_input = wp_get_post_tags($postid, array('fields' => 'names')); if ( is_object_in_taxonomy($post->post_type, 'category') )
} $post->post_category = wp_get_post_categories($postid);
else { $post->tags_input = array();
$post['post_category'] = wp_get_post_categories($postid); if ( is_object_in_taxonomy($post->post_type, 'post_tag') )
$post['tags_input'] = wp_get_post_tags($postid, array('fields' => 'names')); $post->tags_input = wp_get_post_tags($postid, array('fields' => 'names'));
} else {
$post['post_category'] = array();
if ( is_object_in_taxonomy($post['post_type'], 'category') )
$post['post_category'] = wp_get_post_categories($postid);
$post['tags_input'] = array();
if ( is_object_in_taxonomy($post['post_type'], 'post_tag') )
$post['tags_input'] = wp_get_post_tags($postid, array('fields' => 'names'));
} }
return $post; return $post;
@ -2240,9 +2247,10 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
$wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
} }
wp_set_post_categories( $post_ID, $post_category ); if ( is_object_in_taxonomy($post_type, 'category') )
// old-style tags_input wp_set_post_categories( $post_ID, $post_category );
if ( isset( $tags_input ) )
if ( isset( $tags_input ) && is_object_in_taxonomy($post_type, 'post_tag') )
wp_set_post_tags( $post_ID, $tags_input ); wp_set_post_tags( $post_ID, $tags_input );
// new-style support for all custom taxonomies // new-style support for all custom taxonomies