[wp-hackers] Why in the heck won't this work?

DD32 wordpress at dd32.id.au
Thu Aug 23 11:26:24 GMT 2007


Perhaps this will help?

term_taxonomy_id is the Category ID


<?php
$post_ID = 28;

$categories = wp_get_object_terms($post_ID, 'category');

var_dump($categories);
?>

array
    0 =>
      object(stdClass)[165]
        public 'term_id' => string '9' (length=1)
        public 'name' => string 'Test Cat' (length=14)
        public 'slug' => string 'test-cat' (length=14)
        public 'term_group' => string '0' (length=1)
        public 'term_taxonomy_id' => string '9' (length=1)
        public 'taxonomy' => string 'category' (length=8)
        public 'description' => string '' (length=0)
        public 'parent' => string '0' (length=1)
        public 'count' => string '1' (length=1)
    1 =>
      object(stdClass)[166]
        public 'term_id' => string '14' (length=2)
        public 'name' => string 'Wordpress Plugins' (length=17)
        public 'slug' => string 'wordpress-plugins' (length=17)
        public 'term_group' => string '0' (length=1)
        public 'term_taxonomy_id' => string '14' (length=2)
        public 'taxonomy' => string 'category' (length=8)
        public 'description' => string '' (length=0)
        public 'parent' => string '0' (length=1)
        public 'count' => string '1' (length=1)

On Thu, 23 Aug 2007 21:06:10 +1000, Viper007Bond <viper at viper007bond.com>
wrote:

> Perhaps coding at 4am isn't the best idea, I know, but I can't figure out
> for the life of me why this won't work.
>
> I've made of copy of in_category() and modified it slightly to accept the
> post ID rather than getting it from the global $post (due to use in a  
> plugin
> -- I need to find out if a certain post is in a certain category).
>
> My code: http://wordpress.pastebin.com/f5c7e4b6a
>
> The original's $categories array's keys are the values of the category  
> ID.
>
> ex:
>
> Array
> (
>     [6] => stdClass Object
>         (
>             [term_id] => 6
>
>
> However, the one in my function does it sequentially:
>
> Array
> (
>     [0] => stdClass Object
>         (
>             [term_id] => 6
>
>
> Then 1, then 2, etc.
>
> Due to this, the array_key_exists() test is failing.
>
> Any ideas why? I don't see what is making the difference.
>

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the wp-hackers mailing list