从…起http://codex.wordpress.com:
$categories = get_categories( $args );
$args = array(
\'type\' => \'post\',
\'child_of\' => 0,
\'parent\' => \'\',
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => 1,
\'hierarchical\' => 1,
\'exclude\' => \'\',
\'include\' => \'\',
\'number\' => \'\',
\'taxonomy\' => \'category\',
\'pad_counts\' => false
);
我认为“类型”是post类型。但不是。这是要检索的类别类型。我的研究没有成功。
那么,你知道如何检索分配给特定职位类型的所有职位的所有类别吗?
最合适的回答,由SO网友:vmassuchetto 整理而成
适用于任何分类后关系的暴力解决方案:
global $wpdb;
// set the target relationship here
$post_type = \'post\';
$taxonomy = \'category\';
$terms_ids = $wpdb->get_col( $wpdb->prepare( "
SELECT
tt.term_id
FROM
{$wpdb->term_relationships} tr,
{$wpdb->term_taxonomy} tt,
{$wpdb->posts} p
WHERE 1=1
AND tr.object_id = p.id
AND p.post_type = \'%s\'
AND p.post_status = \'publish\'
AND tr.term_taxonomy_id = tt.term_taxonomy_id
AND tt.taxonomy =\'%s\'
", $post_type, $taxonomy ) );
// here you are
$terms = get_terms( $taxonomy, array(
\'include\' => $terms_ids,
\'orderby\' => \'name\',
\'order\' => \'ASC\'
) );