您可以使用wp_get_post_terms()
拉条款。
$taxonomy = \'project-category\';
$terms = wp_get_post_terms( $post->ID, $taxonomy);
var_dump($terms);
wp_get_post_terms()
将返回术语数组,因为可能会将多个术语分配给一篇文章。这意味着您可能会得到一组术语,而不仅仅是一个术语,因此您需要选择使用哪个术语。也就是说,第一个条款?最后一学期?第一个是
$terms[0]->slug
例如您的“模式”就是这样:
\'post_type\' => \'project\',
\'project-category\' => \'Print\',
You can alternately use a tax_query
as found in the Codex:
array(
\'taxonomy\' => \'project-category\',
\'field\' => \'term_id\',
\'terms\' => array( 103, 115, 206 ),
),
在您的情况下,它看起来像:
$taxonomy = \'project-category\';
$terms = wp_get_post_terms( $post->ID, $taxonomy,array("fields" => "ids"));
$query_args = array(
\'post_type\' => \'project\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'project-category\',
\'field\' => \'term_id\',
\'terms\' => $terms,
)
),
\'posts_per_page\' => 2
);