Opened 6 years ago
Closed 5 years ago
#5317 closed defect (bug) (fixed)
get_posts returns invalid data when using category= parameter
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.5 |
| Component: | General | Version: | 2.3.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
Take a new 2.3.1 install with this code:
$myposts = get_posts('category=2');
You would expect to get NO results, as an out-of-the-box install has no posts with category 2, but that code will return the "Hello World!" post.
Guessing this might be caused by get_posts not discerning between post categories and link categories (e.g. the link with link_id=1 in category 2 causes post with ID=1 to be returned).
Attachments (3)
Change History (15)
comment:1
Kafkaesqui
— 6 years ago
comment:2
Kafkaesqui
— 5 years ago
- Milestone changed from 2.4 to 2.3.2
comment:3
Kafkaesqui
— 5 years ago
Changed milestone to 2.3.2, since this is an easy fix to slip in.
comment:4
lloydbudd
— 5 years ago
- Milestone changed from 2.3.2 to 2.4
Kafkaesqui, thank you for your participation! Please don't change the milestones, leave that for the project leads.
comment:5
MichaelH
— 5 years ago
- Keywords has-patch added
+1 for getting this in 2.3.2 -- it's just one less problem to explain in the forums ;)
Patch attached.
comment:7
MichaelH
— 5 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening because [6490] doesn't look to have the complete fix from the 5317_for_24.diff.
comment:10
ryan
— 5 years ago
- Milestone changed from 2.5 to 2.3.3
comment:11
ryan
— 5 years ago
comment:12
DD32
— 5 years ago
- Milestone changed from 2.3.4 to 2.5
- Resolution set to fixed
- Status changed from reopened to closed
2.3.x is dead, 2.5 is stable released, Marking as fixed in 2.5
Line #257 in post.php:
$query .= empty( $category ) ? '' :
AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id
AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
AND $wpdb->term_taxonomy.term_id = " . $category. ") ";
This should be:
$query .= empty( $category ) ? '' :
"AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id
AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
AND $wpdb->term_taxonomy.term_id = " . $category. "
AND $wpdb->term_taxonomy.taxonomy = 'category') ";