[wp-hackers] get_posts bug, or feature?

andrew rader andrew.r.rader at gmail.com
Thu Dec 6 17:23:41 GMT 2007


sorry for the delay, I just got around to verifying this.

Okay, so here's my layout:

3 total categories, with IDs 9, 10, and 11. 9 and 10 are siblings, and
11 is a sub category to 10. Category 10 has no posts, and category 11
has 1 post. if I do get_posts('category=11'), I see that 1 post. if I
do get_posts('category=10') I still see that one post. This is clearly
wrong.

This also happens if I view the categories: ie, if I browse to
site.com/?cat=11 I see the 1 post like I'm supposed, but if I go to
site.com/?cat=10 I still see that post.

this seems like a bug to me, if I wanted sub categories I'd ask for them.

On Dec 4, 2007 1:44 PM, Otto <otto at ottodestruct.com> wrote:
> The get_posts function in post.php doesn't look like it will do what
> you say it's doing. It doesn't merge children into the category part
> of the query. It's adding this to the where clause
>
> AND (wp_posts.ID = wp_term_relationships.object_id AND
> wp_term_relationships.term_taxonomy_id =
> wp_term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id =
> $category)
>
> That's not going to get children categories too.
>
> Are you use that you're not using $wp_query->get_posts() instead?
> Because that behaves differently.
>
>
>
>
> On 12/2/07, andrew rader <andrew.r.rader at gmail.com> wrote:
> > Hi all,
> >
> > I'm revisiting a plugin I've written using WP 2.3.1, and I'm seeing
> > undesired behavior in get_posts.
> >
> > my plugin, fancy-categories, displays the posts in a given category
> > directly in the sidebar list. I use
> > get_posts("numberposts=0&category=$catID") to get the posts of a given
> > category. The problem is that this code returns not only posts in the
> > $catID category, but also posts in the categories that are SUB
> > categories to $catID.
> >
> > the documentation here:
> > http://codex.wordpress.org/Template_Tags/get_posts says that:
> >
> >  category
> >     (integer) Only show posts from this category ID. There is no default.
> >
> > This makes me think that get_posts should only return those posts
> > directly in that category. I also believe this is how it worked prior
> > to 2.3 (but I have yet to verify)
> >
> > is this a bug? or a "feature". If it's intended behavior, I think the
> > get_posts open should allow you to exclude posts in sub-categories
> >
> > thanks,
> > Andy
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list