douluan5444 2015-04-15 21:35
浏览 33

Wordpress:不能使用stdClass类型的对象作为数组

I get this array error

"Fatal error: Cannot use object of type stdClass as array" 

in Wordpress on file category.php. The issue arrives when I don't have any subcategories of a category, so I try to handle if the subcategory list is 0.

But I keep getting the same error, can someone see the error I do here?

The error appears starting in the line:

"if ($category[0]->category_parent == 0) {"

And the whole code within the brackets.

<?php 
                                $args = array(
                                    'type' => 'post',
                                    'child_of' => $cat_id,
                                    'parent' => get_query_var(''),
                                    'orderby' => 'name',
                                    'order' => 'ASC',
                                    'hide_empty' => 0,
                                    'hierarchical' => 1,
                                    'exclude' => '',
                                    'include' => '',
                                    'number' => '',
                                    'taxonomy' => 'category',
                                    'pad_counts' => true );

                                $categories = get_categories($args);


                                        if ($category[0]->category_parent == 0) {

                                            $tag = $category[0]->cat_ID;

                                            $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
                                            if (isset($tag_extra_fields[$tag])) {
                                                $category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
                                                $category_icon_color = $tag_extra_fields[$tag]['category_icon_color'];
                                            }

                                        } else {

                                            $tag = $category[0]->category_parent;

                                            $tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
                                            if (isset($tag_extra_fields[$tag])) {
                                                $category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
                                                $category_icon_color = $tag_extra_fields[$tag]['category_icon_color'];
                                            }

                                        }





                                foreach($categories as $category) { ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么