[wp-hackers] $wp_taxonomies is pretty strange - change appreciated

Andrew Nacin wp at andrewnacin.com
Fri Feb 11 14:47:01 UTC 2011


On Fri, Feb 11, 2011 at 8:55 AM, 24/7 <24-7 at gmx.net> wrote:

> @Jon & Nacin: Thanks. That really caused me some headaches.
>
> I ended up with the following:
> function get_object_types_unique( $all_r_custom = false ) {
>        $tax_object = get_taxonomies( array( '_builtin' => $all_r_custom ),
> 'objects' );
>        if ( $all_r_custom == true )
>                $tax_object = array_merge( $tax_object,
> get_taxonomies( array( '_builtin' => false ), 'objects' ) );
>
>        $object_types = array();
>         foreach ( $tax_object as $tax ) {
>                 $object_types = array_merge( $object_types,
> $tax->object_type );
>        }
>
>        $object_types = array_unique( $object_types );
>        return $object_types;
> }
> The drawback is that i have to ask the DB for twice to retrieve all,
> but it's ok so far.
>

Nothing is stored in the DB. You're working with an internal stateless
array. It's really quick.

Not sure why you're not doing it like this:
(also, always prefix function names)

function nacin_get_object_types_unique( $custom_only = false ) {
       $args = $custom_only ? array( '_builtin' => false ) : array();
       $tax_objects = get_taxonomies( $args, 'objects' );
       ...

Nacin


More information about the wp-hackers mailing list