Ticket #3747 (closed enhancement: fixed)

Opened 1 year ago

Last modified 1 year ago

query.php - get_posts causing ambiguous errors

Reported by: mhyk25 Assigned to: anonymous
Priority: normal Milestone: 2.1.2
Component: General Version: 2.1
Severity: normal Keywords: has-patch commit
Cc:

Description

Table field names without the table name prefixed (e.g. category_id should be $wpdb->post2cat.category_id) are causing MySQL Ambiguous errors when the post2cat table is used in a plugin.

Attachments

query.php.diff (1.0 kB) - added by mhyk25 on 02/04/07 08:34:17.

Change History

02/04/07 08:34:17 changed by mhyk25

  • attachment query.php.diff added.

02/04/07 12:09:04 changed by westi

  • keywords set to reporter-feeback.

Can you provide an example of the plugin code that is causing the error to occur.

I can't see why we need to be that specific in these queries.

02/05/07 14:56:05 changed by mhyk25

A sample scenario could be a plugin allows certain categories to be hidden to guests users, where category ID of the private ones are collected and stored in an object or array in the options table.

posts_join hook function appends this line to make sure that post2cat is used: $join .= " LEFT JOIN $wpdb->post2cat p2c ON $wpdb->posts.ID = p2c.post_id ";

posts_where hook function makes use of this table looping through an array of selected category_ids to hide like so: $where .= ' AND p2c.category_id != ' . $optObj->protected_categories[$x] . ' ';

This is fine when viewing other pages, but viewing a category will result in an ambiguous error. If this sounds crazy and very wrong, I apologize. Just point me in the right direction :P

02/05/07 21:29:43 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

(In [4866]) Disambiguate queries. Props mhyk25. fixes #3747

02/05/07 21:29:58 changed by ryan

  • status changed from closed to reopened.
  • resolution deleted.
  • milestone changed from 2.3 to 2.1.1.

02/05/07 21:30:43 changed by ryan

Fixed in 2.2. Re-opening to see if Mark wants to put this in 2.1.1 since I've seen a few plugin authors complain about this.

02/05/07 22:14:26 changed by markjaquith

Yeah, go for it.

02/21/07 15:33:36 changed by Nazgul

  • keywords changed from reporter-feeback to has-patch commit.
  • milestone changed from 2.1.1 to 2.1.2.

02/23/07 01:04:56 changed by ryan

[4923] for 2.1.2

02/23/07 01:07:49 changed by ryan

  • status changed from reopened to closed.
  • resolution set to fixed.