您应该使用get_terms()
在可能的情况下进行分类。
<?php
/* Add your taxonomy. */
$taxonomies = array(
\'fabric_building_types\',
);
$args = array(
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => true,
\'exclude\' => array(),
\'exclude_tree\' => array(),
\'include\' => array(),
\'number\' => \'\',
\'fields\' => \'all\',
\'slug\' => \'\',
\'parent\' => \'\',
\'hierarchical\' => true,
\'child_of\' => 0,
\'get\' => \'\',
\'name__like\' => \'\',
\'description__like\' => \'\',
\'pad_counts\' => false,
\'offset\' => \'\',
\'search\' => \'\',
\'cache_domain\' => \'core\'
);
$terms = get_terms( $taxonomies, $args );
foreach ( $terms as $term ) {
// here\'s my code for getting the posts for custom post type
$posts_array = get_posts(
array( \'showposts\' => -1,
\'post_type\' => \'fabric_building\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'fabric_building_types\',
\'field\' => \'term_id\',
\'terms\' => $term->term_id,
)
)
)
);
print_r( $posts_array );
}
?>
Link to Codex:
http://codex.wordpress.org/Function_Reference/get_terms