[wp-hackers] Unexpected behaviour in WP_Query

Matt Walters mwalters8 at gmail.com
Wed Feb 4 18:35:55 GMT 2009


I asked about it in #wordpress-dev about a month ago and was told
$post->post_category was fine to use for updating a posts categories,
but it does not retrieve the categories when the object is loaded.
So, not sure it really helps with the issue at hand, but just wanted
to point out it's not a complete fossil yet either.


---------------------------------
Matt Walters




On Wed, Feb 4, 2009 at 1:19 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