你不能自己编造论点,而不是替换\'category\'
参数,使用\'tax_query\'
.
看见"taxonomy parameters" section of the codex on get_posts.
$args = array(
\'post_type\' => \'event\',
\'post_status\' => \'publish\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'eventcategory\',
\'field\' => \'slug\',
\'terms\' => \'nice-events\',
),
),
);
$your_query = get_posts( $args );
// do something with $your_query
或者,您可以使用
WP_Query
类别:
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'event\',
\'post_status\' => \'publish\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'eventcategory\',
\'field\' => \'slug\',
\'terms\' => \'nice-events\'
),
),
);
$your_query = new WP_Query( $args );
// do something with $your_query