/* This foreach is used to grab records from WordPress */
foreach ($offices as $office) {
/* Set the wordpress offices as an array */
$id = get_post_meta($office->ID, '_office_id', true);
/* If there are $ids, then set the $id as the key */
if ($id != '') {
$ids[$id] = $office;
}
}
/* This foreach is used to grab records from an API */
foreach ($records as $record) {
/* Define the variable as the octopus id */
$octopus_id = $record->id;
/* Sets an variable to combine the location id and business unit */
$record_key = strtoupper(str_replace(' ', '',
trim($record->location_id) . trim($record->business_unit)));
/* Checks to see if $ids is set or empty */
if (isset($ids) & !empty($ids)) {
/* Check if the record key exists in the ids array */
if (array_key_exists($record_key, $ids)) {
/* Check if an Octopus ID exists */
if (!isset($octopus_id) || empty($octopus_id)) {
update_post_meta($ids, '_id', $record->id);
} else {
echo $record . ' has not been updated.';
}
} else {
echo '<b>' . $record_key . ' doesnt have a record in WordPress. The octopus id is: ' . $octopus_id . '</b><br/>';
}
}
}
Привет всем,
Может ли кто-нибудь объяснить мне, как я смогу использовать update_post_meta для if (!isset($octopus_id) || empty($octopus_id)) {
, если он основан на другом foreach? Вид застрял в этой части.
Это дает мне ошибку Expected int, got array
на update_post_meta ($ ids, часть.
![enter image description here](https://i.stack.imgur.com/SJ8VG.png)