我有下面的get方法,我想用它作为模板,将我的类别名称输出到输出方法中:
public static function get()
{
$recipe_categories = get_terms(\'recipe_categories\');
var_dump($recipe_categories);
foreach ($recipe_categories as $member_group_term) {
$member_group_query = new WP_Query( array(
\'post_type\' => \'recipe\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'recipe_categories\',
\'field\' => \'slug\',
\'terms\' => array($member_group_term->slug),
\'operator\' => \'IN\'
)
)
));
var_dump($member_group_query);
}
}
以下是我的输出方法:
public function output()
{
// @todo: Grab get() and output
}
我无法让它打印出所有“name”属性:
以下是我得到的信息:
SO网友:Cadu De Castro Alves
您可以使用wp_pluck_list 像这样:
wp_pluck_list($recipe_categories, \'name\');
应返回:
array(
\'Bread\',
\'Breakfast\',
\'Cocktails\'
)