¿Cómo obtener todas las taxonomías de un tipo de publicación?

39

¿Cómo puedo obtener taxonomías de un tipo de publicación?

Si tengo un tipo de publicación event y necesito encontrar la lista de taxonomías que se adjuntan a ese tipo de publicación. ¿Cómo los encuentro?

    
pregunta Sisir 21.06.2011 - 11:20

3 respuestas

32

Hola chicos, creo que lo tengo! Después de ver un par de funciones en el archivo taxonomy.php en WordPress, he encontrado esta función get_object_taxonomies(); que hizo el truco :)

Aquí está la función

function get_post_taxonomies($post) {
    // Passing an object
    // Why another var?? $output = 'objects'; // name / objects
    $taxonomies = get_object_taxonomies($post, 'objects');

    /*// Passing a string using get_post_type: return (string) post, page, custom...
    $post_type  = get_post_type($post);
    $taxonomies = get_object_taxonomies($post_type, 'objects');*/

    /*// In the loop with the ID
    $theID      = get_the_ID();
    $post_type  = get_post_type($theID);
    $taxonomies = get_object_taxonomies($post_type, 'objects');*/

    // You can also use the global $post

    // edited to fix previous error $taxonomies
    // edited to force type hinting array
    return (array) $taxonomies; // returning array of taxonomies
}
    
respondido por el Sisir 21.06.2011 - 15:06
9

get_categories hará el trabajo.

get_categories('taxonomy=taxonomy_name&type=custom_post_type'); 
    
respondido por el addedlovely 21.06.2011 - 13:46
1

¿Has probado algo? algo como esto?

<?php 

$args=array(
  'object_type' => array('event') 
); 

$output = 'names'; // or objects
$operator = 'and'; // 'and' or 'or'
$taxonomies=get_taxonomies($args,$output,$operator); 
if  ($taxonomies) {
  foreach ($taxonomies  as $taxonomy ) {
    echo '<p>'. $taxonomy. '</p>';
  }
}
?>
    
respondido por el Reigel 21.06.2011 - 11:31

Lea otras preguntas en las etiquetas