WordPress.org

Make WordPress Core

Ticket #9009: 9009-enhanced.diff

File 9009-enhanced.diff, 924 bytes (added by Denis-de-Bernardy, 5 years ago)
  • Users/denis/Sites/sem-pro/wp-includes/post.php

     
    667667 */ 
    668668function delete_post_meta_by_key($post_meta_key) { 
    669669        global $wpdb; 
    670         if ( $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key)) ) { 
    671                 /** @todo Get post_ids and delete cache */ 
    672                 // wp_cache_delete($post_id, 'post_meta'); 
     670        $post_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key LIKE %s", $post_meta_key)); 
     671        if ( $post_ids ) { 
     672                $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key LIKE %s", $post_meta_key)); 
     673                foreach ( $post_ids as $post_id ) 
     674                        wp_cache_delete($post_id, 'post_meta'); 
    673675                return true; 
    674676        } 
    675677        return false;