我在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