我正在尝试在Wordpress中自定义插件,编写了代码以列出从DB中获取的数据,在Json解码数组被列出之后,但是我尝试使用for和for每个循环,因为两者都没有列出没有显示错误,只是空白。
Wordpress页面模板-
<?php
/**
* Template Name: List Guide
*/
get_header();
?>
<?php
$query = $wpdb->prepare(
"SELECT
post_content
FROM
wp_posts
WHERE
ID = 7
",
$ID
);
$string = $wpdb->get_var( $query );
$someArray = json_decode( $string );
print_r($someArray);
die;
echo $count = count( $someArray );
for ( $i = 0; $i < $count; $i++ ) { ?>
<?php echo $someArray->locations[$i]->title; ?>
<?php } ?>
<?php
get_footer();
?>
Array([mapwidth] => 637 [mapheight] => 586 [minimap] => [清除按钮] => 1 [缩放按钮] => 1 [侧边栏] => 1 [搜索] => 1 [hovertip] => 1 [mousewheel] => 1 [fullscreen] => [deeplinking] => 1 [mapfill] => [zoom] => 1 [alphabetic] => 1 [zoomlimit] => 3 [action] =>工具提示[类别] =>数组([0] =>数组([id] =>服装[title] =>服装[color] => [show] => false)[1] => Array([id ] =>首饰和配件[标题] =>珠宝和配饰[颜色] => [显示] =>假)[2] =>阵列([id] =>鞋子[标题] =>鞋子 [color] => [show] => false)[3] => Array([id] => beautyandhealth [title] =>美容与健康[color] => [show] => false)[4] => Array( [id] =>适合度[title] => FITNESS [color] => [show] => false)[5] => 数组([id] => restaurantandcafe [title] =>餐馆和咖啡厅 [color] => [show] => false)[6] => Array([id] => homeanddesign [title] => HOME&DESIGN [color] => [show] => false)[7] => Array( [id] => hotelsandhospitality [title] => HOTELS&HOSPITALITY [颜色] => [显示] =>假)[8] =>数组([id] => artgalleries [title] => ART GALLERIES [color] => [show] =>假)[9] =>数组([id ] => Specialtyandother [title] => SPECIALTY&OTHER [color] => [show] => false))[levels] => Array([0] => Array([id] => soho001 [title] => Soho [map] => //dotzserver.com/soho/wp-content/uploads/2018/05/Map-for-Web_V21.svg [minimap] => [locations] => Array([0] => Array([id] => location965 [title] => Rag&Bone [description] =>
[pin] =>紫色不填充[link] => https://www.rag-bone.com/ [类别] =>服装[动作] =>默认[x] => 0.5018 [y] => 0.4627 [填充] => #ffffff)[1] =>数组([id] => location133 [title] => Near Subway [固定] =>不填写[填充] => #ffffff [类别] => restaurantandcafe [操作] =>默认[x] => 0.5021 [y] => 0.3250)[2] =>数组([id] => location359 [title] => Yay [pin] =>黄色不填充[fill] => #ffffff [类别] => homeanddesign [action] =>默认[x] => 0.4194 [y] => 0.3798) )))[maxscale] => 3 [zoomoutclose] => [fillcolor] =>
8224e3 [topLat] => [leftLng] => [bottomLat] => [rightLng] => [smartip] => [thumbholder] => [height] => auto)28
答案 0 :(得分:0)
已解决
要调用的数组的格式为-
foreach ($someArray['levels'] as $arr){
foreach ($arr['locations'] as $locationarr){
echo $locationarr['title']
}
}