从var_dump
获取值:
mymeta_url_group =>
0 => string(39) "a:1:{s:10:"mymeta_url";s:8:"You rock";}"
1 => string(40) "a:1:{s:10:"mymeta_url";s:9:"Yeah Sure";}"
我用过:
$urls= get_post_meta( get_the_ID(), 'mymeta_url_group', false );
foreach ( $urls as $url)
{
echo $url["mymeta_url"];
// You Rock
//Yeah Sure
}
现在,因为我在后端添加了转发器和分拣机选项,所以新的转储显示:
mymeta_url_group =>
0 => string(102) "a:1:{s:10:"mymeta_url";a:2:{s:11:"cmb-field-0";s:8:"You rock";s:11:"cmb-field-1";s:11:"Nope Maybe ";}}"
1 => string(100) "a:1:{s:10:"mymeta_url";a:2:{s:11:"cmb-field-0";s:9:"Yeah Sure";s:11:"cmb-field-1";s:9:"Won't you";}}"
现在我怎样才能获得价值观“你摇滚”“不可能”“是的”“你不会”扩展我以前的解决方案。
PS如果我做var_dump($url["mymeta_url"]);
输出是
Arrayarray(2) { ["cmb-field-0"]=> string(8) "You rock" ["cmb-field-1"]=> string(11) "Nope Maybe " } Arrayarray(2) { ["cmb-field-0"]=> string(9) "Yeah Sure" ["cmb-field-1"]=> string(9) "Won't you" }
答案 0 :(得分:0)
以下是我提出的建议:
foreach($array as $array2) { //If it doesn't work change $array to $array['mymeta_url_group']
$array2 = unserialize($array2);
foreach($array2['mymeta_url'] as $line) {
echo $line; //$line is the sentance you're looking for
}
}
我不确定是否会起作用,因为我必须从var_dump()
输出重建数组。
答案 1 :(得分:0)
我不知道get_post_meta()
应该做什么,但也许这会给你一些想法:
<?php
/* Setting up data */
$data = array (
'a:1:{s:10:"mymeta_url";a:2:{s:11:"cmb-field-0";s:8:"You rock";s:11:"cmb-field-1";s:11:"Nope Maybe ";}}',
'a:1:{s:10:"mymeta_url";a:2:{s:11:"cmb-field-0";s:9:"Yeah Sure";s:11:"cmb-field-1";s:9:"Won\'t you";}}'
);
$urls = array();
foreach ($data as $s) {
$urls[] = unserialize ($s);
}
/* Retrieving data */
foreach ($urls as $url) {
foreach ($url['mymeta_url'] as $u) {
echo "$u, ";
}
echo "\n";
}