Make WordPress Core


Ignore:
Timestamp:
05/27/2007 05:15:18 AM (16 years ago)
Author:
ryan
Message:

Fix object term relationship deletion and count updating.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r5555 r5556  
    411411    do_action('delete_post', $postid);
    412412
    413     if ( 'publish' == $post->post_status && 'post' == $post->post_type ) {
    414         $categories = wp_get_post_categories($post->ID);
    415         if ( is_array( $categories ) ) {
    416             foreach ( $categories as $cat_id ) {
    417                 $wpdb->query("UPDATE $wpdb->categories SET category_count = category_count - 1 WHERE cat_ID = '$cat_id'");
    418                 wp_cache_delete($cat_id, 'category');
    419                 do_action('edit_category', $cat_id);
    420             }
    421         }
    422     }
     413    // TODO delete for pluggable post taxonomies too
     414    wp_delete_object_term_relationships($postid, array('category', 'post_tag'));
    423415
    424416    if ( 'page' == $post->post_type )
     
    430422
    431423    $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID = $postid");
    432 
    433     $wpdb->query("DELETE FROM $wpdb->post2cat WHERE post_id = $postid");
    434424
    435425    $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid");
     
    445435}
    446436
    447 function wp_get_post_categories($post_id = 0) {
     437function wp_get_post_categories( $post_id = 0, $args = array() ) {
    448438    $post_id = (int) $post_id;
    449439
    450     $cats = get_object_terms($post_id, 'category', 'get=fields');
     440    $defaults = array('fields' => 'ids');
     441    $args = wp_parse_args( $args, $defaults );
     442
     443    $cats = get_object_terms($post_id, 'category', $args);
    451444    return $cats;
    452445}
    453446
    454 function wp_get_post_tags( $post_id = 0 ) {
    455     global $tag_cache, $blog_id;
    456 
     447function wp_get_post_tags( $post_id = 0, $args = array() ) {
    457448    $post_id = (int) $post_id;
     449
     450    $defaults = array('fields' => 'all');
     451    $args = wp_parse_args( $args, $defaults );
    458452   
    459     $tags = get_object_terms($post_id, 'post_tag');
     453    $tags = get_object_terms($post_id, 'post_tag', $args);
     454
    460455    return $tags;
    461456}
Note: See TracChangeset for help on using the changeset viewer.