[wp-hackers] Unexpected behaviour in WP_Query

Sudar Muthu sudar at sudarmuthu.com
Wed Feb 4 18:22:33 GMT 2009


>
> I think $post->post_category is a fossil from older versions and doesn't
>
serve any purpose.
>

If that is the case, then is there a way to retrieve the category of the
post without using wp_get_post_categories($post->ID); function call?

With Regards,
Sudar

http://SudarMuthu.com
http://twitter.com/sudarmuthu


On Wed, Feb 4, 2009 at 11:49 PM, scribu <scribu at gmail.com> wrote:

> I think $post->post_category is a fossil from older versions and doesn't
> serve any purpose.
>
> On Wed, Feb 4, 2009 at 8:13 PM, Sudar Muthu <sudar at sudarmuthu.com> wrote:
>
> > Hello all,
> >
> > I was playing with WP_Query and found an unexpected behaviour. I am not
> > sure
> > whether this is the expected behaviour or it is a bug. And if it is a
> bug,
> > I
> > will open a new ticket in trac.
> >
> > This is the code which I am using in one of my Plugins to retrieve the
> > posts
> > belonging to a particular category. Both code and output available in
> > pastebin as well at http://pastebin.com/m46539116
> >
> > $my_query = new WP_Query;
> >
> > $posts = $my_query->query(array('category__in'=>array($cat_id),
> > 'post_type'=>'post', 'nopaging'=>'true'));
> >
> > print_r($posts);
> >
> > And in the output I have the following line
> >
> > [post_category] => 0
> >
> >
> >
> > So the function is retrieving the posts, but in the result, the category
> is
> > 0. I tried to trace the SQL generated in this case and it is available in
> > pastebin at http://pastebin.com/m7a889bdc
> >
> > The category is 0 even when I execute the generated SQL directly in my
> > database.
> >
> > I strongly feel that it is a bug. So please let me know whether it is a
> bug
> > or it an expected behaviour. Thanks!
> >
> >
> > With Regards,
> > Sudar
> > http://SudarMuthu.com
> > http://twitter.com/sudarmuthu
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
>
>
>
> --
> http://scribu.net
> _______________________________________________
> 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