$postList = Post::getPostList([
'join' => [
'category',
'author',
],
]);
foreach($postList as $post) {
// то есть маппер у вас уже эти данные получил и перед отдачей объектов инициализировал их
$post->getCategoryName();
$post->getAuthorName();
}
$view->render($postList);
$postList = Post::getPostList();
$postIds = array_column($postList, 'id');
$categoryNames = Category::getNamesWherePostId($postIds);
$authorNames = User::getNamesWherePostId($postIds);
foreach($postList as $post) {
$post['category_name'] = $categoryNames[$post->categoryId] ?? null;
$post['author_name'] = $authorNames[$post->authorId] ?? null;
}
$view->render($postList);
$arr_tovar = $result->products;
$params = [
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'admin:123123123' )
),
'body' => [],
];
foreach ($arr_tovar as $item) {
$params['body'][] = array(
'name' => $item->name,
'status' => 'pending',
'categories' => array(
array(
'id_iiko_категории' => $item->productCategoryId
)
),
'regular_price' => $item->price
);
}
$api_response = wp_remote_post( $url_site.'/wp-json/wc/v3/products', $params);
$body = json_decode( $api_response['body'] );
if( wp_remote_retrieve_response_message( $api_response ) === 'Created' ) {
echo 'The product ' . $body->name . ' has been created';
}
print_r( $body );