[wp-hackers] get_posts bug, or feature?
Otto
otto at ottodestruct.com
Thu Dec 6 18:25:40 GMT 2007
Add define('SAVEQUERIES', true); to your wp-config.php file.
Then somewhere in your theme, you can dump the queries to the output.
Like add this to the footer.php file:
<?php echo "<!--\n"; var_dump($wpdb->queries); echo "\n-->"; ?>
Then load the page showing the problem, view source, and all the SQL
you ran will be at the bottom of the page.
Remove the SAVEQUERIES afterwards, it's a bit of a performance hit to
leave it on.
On 12/6/07, andrew rader <andrew.r.rader at gmail.com> wrote:
> yes, I am using get_posts:
>
> $p = get_posts('category=10'); echo $p[0]->post_title;
>
> I have no idea how get_posts is doing this, but it definitely is. How
> can I turn on query logging?
>
> On Dec 6, 2007 9:51 AM, Otto <otto at ottodestruct.com> wrote:
> > Okay, I'm confused. Are you using get_posts or not?
> >
> > >From looking at the code, I don't think get_posts will return children.
> > However, query_posts will indeed do just that.
> >
> > So your links with cat=11 and cat=10 will indeed behave the way you're
> > saying, but I can't see how get_posts() will do what you're talking
> > about. If you say it is, then it is, but I can't see how it could.
> >
> > Maybe if you turned on query logging and logged the actual SQL that
> > occurs on your get_posts() call, we could figure it out.
> >
> >
> >
> > On 12/6/07, andrew rader <andrew.r.rader at gmail.com> wrote:
> > > 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
> > > >
> > > _______________________________________________
> > > 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
> >
> _______________________________________________
> 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