<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://tariff.pochta.ru/v2/calculate/tariff/delivery?json=null&weight=60&from=685000&to=101000&object=4030&closed=0',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
function smart_category_top_parent_id ($catid) {
while ($catid) {
$cat = get_category($catid); // get the object for the catid
$catid = $cat->category_parent; // assign parent ID (if exists) to $catid
// the while loop will continue whilst there is a $catid
// when there is no longer a parent $catid will be NULL so we can assign our $catParent
$catParent = $cat->cat_ID;
}
return $catParent;
}
$category = get_the_category($post->ID); //post id
$catid = $category[0]->cat_ID;
$top_level_cat = smart_category_top_parent_id ($catid);