我在wordpress自定义帖子类型中有一个可重复字段,该类型链接到另一个wordpress自定义帖子类型。我想遍历可重复的字段,然后为每个字段访问链接的帖子类型中的数据。第一个结果返回,但在第二个我得到以下错误:尝试输出数组时出现PHP错误
Fatal error : [] operator not supported for strings.
我想从我的变量,比如$员工= $教练[“team_staff”]去掉括号,但没有奏效。
我也尝试设置$ staff = array();之前的循环,并没有奏效。
不知道我有什么错在这里:
global $post;
// Get The Staff Members
$coaches = get_post_meta($post->ID, 'repeatable_fields', true);
if ($coaches) :
foreach ($coaches as $coach) :
$staff[] = $coach['team_staff'];
$role[] = $coach['team_role'];
// Loop through each staff member
foreach($staff as $index => $staff) :
$args = array (
'post_type' => 'staff',
'title' => $staff
);
$posts = get_posts($args);
foreach ($posts as $post) : setup_postdata ($post);
// get post meta here
endforeach;
endforeach;
endforeach;
endif;
可能的重复:https://stackoverflow.com/questions/5879675/problem-with-fatal-error-operator-not-supported-for-strings-in – RToyo
可能的重复[问题与:致命错误:\ [\]运算符不支持字符串](https://stackoverflow.com/questions/5879675/problem-with-fatal-error-operator-not-supported-for-strings-in) – aynber
我注释了$角色[ ] = $ coach ['team_role'];并仍然出现错误。我尝试了上述文章的答案,并从$ staff = $ coach ['team_staff']中删除了[];并获得一个错误。 – RiotAct