您可以使用$wp_taxonomies
已经我只是把它写了下来,所以您可能需要尝试一下,以启动并运行以下代码行,但它应该让您了解它应该如何工作(将其视为参考/伪代码):
编辑:在来自的注释之后Mike Schinkel 我更新了代码,以便更容易忽略内置分类法(请参阅:\\u builtin)。我希望Mike在这里发布他发给我的示例,这样他的(更简单的)解决方案可以标记为最终方法。。。
// equals the following $keys
$wp_taxonomies[\'category\'] == $wp_taxonomies[0];
$wp_taxonomies[\'post_tag\'] == $wp_taxonomies[1];
$wp_taxonomies[\'nav_menu\'] == $wp_taxonomies[2];
$wp_taxonomies[\'link_category\'] == $wp_taxonomies[3];
// after $key #3 you retrieve all different registered taxonomies
$all_tax = count($wp_taxonomies)-4; // gives you the amount of reg. tax.
// Here starts the actual code
$post_types = array(); // some empty array to save your post types for further procesing
$i = 0;
foreach ( $wp_taxonomies as $tax ) {
if ( !$tax->_builtin)
$post_type_arr = $tax[$i]->object_type; // array of post types in the current taxonomy
foreach ( $post_type_arr as $arr ) : // loop through all post types assigned to the taxonomy
$post_types[] .= $arr; // assign them to our array of post types
endforeach;
$i++;
}
$post_types = array_unique($post_types); // drop doublettes out of the array
var_dump($post_types);
# expected result close to this...
# Array(
# 1 => $post_type_a,
# 2 => $post_type_b,
# 3 => $post_type_n
# );