[wp-trac] [WordPress Trac] #50046: lack table selector in `_update_post_term_count`

WordPress Trac noreply at wordpress.org
Fri May 1 15:18:52 UTC 2020


#50046: lack table selector in `_update_post_term_count`
--------------------------+-----------------------------
 Reporter:  yaquawa       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.4
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The function `_update_post_term_count` in `wp-includes/taxonomy.php` query
 the db without table selector.

 {{{#!php
 <?php
 $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM
 $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID =
 $wpdb->term_relationships.object_id AND post_status = 'publish' AND
 post_type IN ('" . implode( "', '", $object_types ) . "') AND
 term_taxonomy_id = %d", $term ) );
 }}}

 This cause problem if who added a column named `post_type` in the
 `$wpdb->term_relationships` table, because the table `$wpdb->posts` has a
 column called `post_type` too.

 Please quantify the column with the table name like
 `$wpdb->posts.post_type`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50046>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list