admin管理员组文章数量:1390784
I have the below get method that I would like to use as a template to output my category names into an output method:
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);
}
}
Here is the output method that I have:
public function output()
{
// @todo: Grab get() and output
}
I can't get it to print out all the 'name' attributes:
Here is what i'm getting:
I have the below get method that I would like to use as a template to output my category names into an output method:
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);
}
}
Here is the output method that I have:
public function output()
{
// @todo: Grab get() and output
}
I can't get it to print out all the 'name' attributes:
Here is what i'm getting:
1 Answer
Reset to default 1You can use wp_pluck_list like so:
wp_pluck_list($recipe_categories, 'name');
Which should return:
array(
'Bread',
'Breakfast',
'Cocktails'
)
本文标签: phpUse get() method to grab all categories and output inside another method
版权声明:本文标题:php - Use get() method to grab all categories and output inside another method 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744753956a2623347.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论