Opened 15 years ago
Closed 12 years ago
#10908 closed enhancement (duplicate)
Impossible to exclude categries in a category listing
Reported by: | dimitryz | Owned by: | ryan |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.8 |
Component: | Query | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
Setting the 'category__not_in' query_var
in a WP_Query
object does nothing if 'category_name' is also present. The consequence is that it's impossible to hide the posts of some child categories for a category listing.
The offending code is in line 1843:
$whichcat = " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
A dot (.) should be added before the equal (=) to indicate concatenation:
$whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
The proposed solution enabled the addition of categories ('category__in') and exclusion of categories ('category__not_in') when the following condition is met:
if ( '' != $q['category_name'] && !$this->is_singular ) {
Attachments (1)
Change History (14)
#3
@
15 years ago
When you're listing the posts for a category. Currently, all posts for that category and posts for that category's children are displayed. If you wanted to exclude the posts of one or more child categories, 'category__not_in' should do the trick.
#4
@
15 years ago
You can use 'postsnot_in' instead, as I'm pretty sure allowing 'categorynot_in' together with 'category_name' will have hidden side effects.
#5
@
15 years ago
I'm not sure about scribu's answer. Excluding posts is more trouble since those posts must first be retrieved. That may be a *lot* of posts.
I also don't understand that you mean by category_name. 'category__not_in' is used with an array of term_ids, not names.
#6
@
15 years ago
- Milestone changed from Unassigned to 3.0
- Type changed from feature request to enhancement
I can see the use-case for this now.
Also see #12891
#7
@
15 years ago
- Keywords has-patch needs-testing added; category wp_query category__not_in removed
#9
@
14 years ago
- Cc upyup added
- Keywords category wp_query category__not_in added; has-patch needs-testing removed
- Type changed from enhancement to feature request
- Version changed from 2.8.4 to 3.1
I have the same problem on v3.0.1
the goal being to set a user filter on specific categories (chosen in the plugin options page)
If the user chose the category 4 ("Adultes" categorie) and then goes to /category/adultes , he is presented the posts from this categories instead of the expected "No post found" page
When changing line 1938
$whichcat = " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
into
$whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
the filter works as a charm
#10
@
14 years ago
- Keywords reporter-feedback added; category wp_query category__not_in removed
- Type changed from feature request to enhancement
- Version changed from 3.1 to 2.8
Please try it with version 3.1-alpha.
'Version' represents the earliest version in which the bug is reproducible.
What would be the use-case of this?
category_name is asking to query for a specific item, category__not_in is saying, for the following generic query, i do not want the following items to be there.. When would they be used together?