Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#10014 closed defect (bug) (invalid)

Select multiple categories doesn't work

Reported by: csseur3's profile csseur3 Owned by: filosofo's profile filosofo
Milestone: Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: categories
Focuses: Cc:

Description

i read this before:

http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query#Query_based_on_Custom_Field_and_Category

and i try to make:

<?php
$test_count = $wpdb->get_var("SELECT SUM(meta_value+0) FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE $wpdb->term_taxonomy.term_id = 97,60,61,134,89
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->postmeta.meta_key = 'adherents'
ORDER BY $wpdb->postmeta.meta_value ASC");
echo '' . $test_count . '';
?>

or

<?php
$test_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE $wpdb->term_taxonomy.term_id = 97,60,61,134,89
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->postmeta.meta_key = 'adherents'
ORDER BY $wpdb->postmeta.meta_value ASC");
echo '' . $test_count . '';
?>

to count number of "adherents" or number of the posts.

There is no working: it is impossible to select multiple categories.

Change History (3)

#1 @filosofo
16 years ago

  • Milestone 2.8 deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 2.7.1 deleted

Hello csseur3,

Trac is meant for reporting WordPress bugs. This is a support question, which you should take to the support forum.

Besides, what we have here is probably bad advice in the Codex. Please keep in mind that anybody can edit the Codex, so that means both that there can be bad advice and that you don't need to open a Trac ticket to resolve it.

One obvious problem is this phrase:

$wpdb->term_taxonomy.term_id = 97,60,61,134,89

which should probably be

$wpdb->term_taxonomy.term_id IN (97,60,61,134,89)

The proposed solutions are likely not the best way to go about accomplishing your goal, but again that's an issue for the support forums, not the bug tracker.

#2 follow-up: @csseur3
16 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Same problem with your solution :(

I know that the forum is for support question, but i describe my problem 1 month ago and again this week, and nobody have solution, so i think there is a bug :(

#3 in reply to: ↑ 2 @filosofo
16 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Replying to csseur3:

I know that the forum is for support question, but i describe my problem 1 month ago and again this week, and nobody have solution, so i think there is a bug :(

Your problems are an incorrectly-formed MySQL query here and more generally an apparent ignorance of the WordPress API. Neither is a WordPress bug, so they are inappropriate in a Trac ticket.

I posted a solution to your question on the support forum.

Note: See TracTickets for help on using tickets.