Answers:
嘿,我想我明白了!在查看了WordPress中taxonomy.php文件中的几个函数后,我发现此函数起到了作用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
}
for
or foreach
循环对它们进行排序。
$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>
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();
法典上的功能,但它的文档非常差,不知道我如何传递帖子类型。