php - Use get() method to grab all categories and output inside another method

I have the below get method that I would like to use as a template to output my category names into an output method:pub

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:

Share Improve this question asked Feb 12, 2020 at 14:19 DevSemDevSem 2092 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can use wp_pluck_list like so:

wp_pluck_list($recipe_categories, 'name');

Which should return:

array(
    'Bread',
    'Breakfast',
    'Cocktails'
)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744753956a4591766.html

相关推荐

  • php - Use get() method to grab all categories and output inside another method

    I have the below get method that I would like to use as a template to output my category names into an output method:pub

    20小时前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信