Как я могу получить taxonomies типа сообщения?
Если у меня есть тип сообщения event
и я должен узнать список taxonomies, которые присоединены к тому типу сообщения. Как я нахожу их?
Я думаю, что у меня есть он! После рассмотрения нескольких функций в taxonomy.php файле в WordPress я нашел функцию get_object_taxonomies();
который добился цели :)
Вот функция:
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
}
get_categories сделает задание.
get_categories('taxonomy=taxonomy_name&type=custom_post_type');
Вы попробовали что-нибудь? что-то вроде этого?
<?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>';
}
}
?>
get_taxonomies();
функция на кодексе, но это имеет очень плохую документацию и не было никакой идеей, как я могу передать типы сообщения.
– Sisir
21.06.2011, 12:56
for
илиforeach
цикл. – Sisir 19.10.2015, 12:25$taxonomies = get_object_taxonomies( array( 'post_type' => $post_type ) ); foreach( $taxonomies as $taxonomy ) : // Gets every "category" (term) in this taxonomy to get the respective posts $terms = get_terms( $taxonomy ); ?> <ul class="specials"><?php foreach( $terms as $term ) : ?> <li><h2 ><?php echo $term->name; ?></h2>
– dh47 19.10.2015, 13:19