如何将类别名称回显到数组 wordpress 中 [英] How to echo category names into an array wordpress
本文介绍了如何将类别名称回显到数组 wordpress 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将类别名称放入以下数组
I am trying to get the category names into the following array
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
$this->settings['categoriesmain1'] = array(
'section' => 'general',
'title' => __( 'Example Select' ),
'desc' => __( 'This is a description for the drop-down.' ),
'type' => 'select',
'std' => '',
'choices' => array(
$categories => $categories // here i am trying to echo them
)
);
choices
默认情况下它们是这样的
choices
by default they are smth like this
'choices' => array(
'Choice 1' => 'Other Choice 1',
'Choice 2' => 'Other Choice 2',
'Choice 3' => 'Other Choice 3'
)
但是当我尝试用 $categories => 回应它们时$categories
我收到错误 Illegal offset type
But when i try to echo them with $categories => $categories
I get error Illegal offset type
推荐答案
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
);
$categories = get_categories($args);
$categories_name = array();
foreach($categories as $category){
$categories_name[] = $category->name;
}
$this->settings['categoriesmain1'] = array(
'section' => 'general',
'title' => __( 'Example Select' ),
'desc' => __( 'This is a description for the drop-down.' ),
'type' => 'select',
'std' => '',
'choices' => $categories_name
)
);
$settings = get_option('mytheme_options');
$my_choices = $settings['categoriesmain1'];
var_dump($my_choices);
这篇关于如何将类别名称回显到数组 wordpress 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文