<ul>
<?php
$custom_query = new WP_Query(array(
'post_type' => 'vse_ob_ekti',
'posts_per_page' => -1,
));
if ($custom_query->have_posts()) {
$object_types = array();
while ($custom_query->have_posts()) {
$custom_query->the_post();
// Получите значение кастомного поля 'object_type' с помощью ACF
$object_type = get_field('object_type');
if ($object_type && isset($object_type['value']) && isset($object_type['label'])) {
$object_types[$object_type['value']] = $object_type['label'];
}
}
wp_reset_postdata();
// Вывод начальных значений и скрытие остальных
foreach (array_reverse($object_types) as $value => $label) {
$is_initial_value = in_array($label, array('Таунхаусы', 'Квартиры, апартаменты', 'Дома, виллы, коттеджи'));
$class = $is_initial_value ? '' : 'hidden no-popular';
// Подсчет количества записей для текущего значения
$count = array_count_values(array_column($object_types, $value));
//var_dump($object_types, $value, $count);
echo '<li class="select__type-item ' . $class . '" data-value="' . esc_attr($value) . '"><span class="item-text" style="margin-right: 10px" data-label="' . esc_attr($label) . '">' . esc_html($label) . '</span>' . $count[$value] . '</li>';
}
echo '<li class="show-more show-button">Показать все</li>';
echo '<li class="hide-more show-button">Показать популярные</li>';
}
?>
</ul> array(10) { ["newbuildings"]=> string(22) "Новостройки" ["flat"]=> string(40) "Квартиры, апартаменты" ["house"]=> string(38) "Дома, виллы, коттеджи" ["condominiums"]=> string(24) "Кондоминиумы" ["arenda"]=> string(36) "Квартиры под аренду" ["land"]=> string(33) "Земельные участки" ["islands"]=> string(14) "Острова" ["chalet"]=> string(8) "Шале" ["castle"]=> string(10) "Замки" ["townhouse"]=> string(18) "Таунхаусы" } string(9) "townhouse" array(0) { }
Warning: Undefined array key "townhouse" in "_embedded" => [
'tags' => [
['name' => $tag],
],
], array(2) { ["content"]=> NULL ["status_code"]=> int(402) } array(2) { ["content"]=> array(4) { ["title"]=> string(9) "Not Found" ["type"]=> string(25) "https://httpstatus.es/404" ["status"]=> int(404) ["detail"]=> string(53) "Cannot POST https://subdomain.amocrm.ru/leads//notes!" } ["status_code"]=> int(404) } 
$method = "/api/v4/leads/complex";
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $access_token,
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-API-client/1.0');
curl_setopt($curl, CURLOPT_URL, "https://$subdomain.amocrm.ru".$method);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, 'amo/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, 'amo/cookie.txt');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$out = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$code = (int) $code;
$errors = [
301 => 'Moved permanently.',
400 => 'Wrong structure of the array of transmitted data, or invalid identifiers of custom fields.',
401 => 'Not Authorized. There is no account information on the server. You need to make a request to another server on the transmitted IP.',
403 => 'The account is blocked, for repeatedly exceeding the number of requests per second.',
404 => 'Not found.',
500 => 'Internal server error.',
502 => 'Bad gateway.',
503 => 'Service unavailable.'
];
if ($code < 200 || $code > 204) die( "Error $code. " . (isset($errors[$code]) ? $errors[$code] : 'Undefined error') );
$Response = json_decode($out, true);
$Response = $Response['_embedded']['items'];
$output = 'ID добавленных элементов списков:' . PHP_EOL;
foreach ($Response as $v)
if (is_array($v))
$output .= $v['id'] . PHP_EOL;
return $output;
Магазин уже функционирующий, есть уже с сотню вбитых товаров именно таким образом. По какой причине не подходит базовый вариативный товар также описано в предыдущем комментарии. Поэтому плагин объединения в данном случае более подходящий вариант.
По ссылке из первого комментария наверное только WPC Linked Variation for WooCommerce подходит по смыслу. Буду пробовать - позволяет ли функционал сделать то что надо. Дам обратную связь.