다음을 사용하여 Wordpress Woocommerce 제품에 대한 데이터를 가져옵니다. json에서 제품 데이터를 출력합니다.Wordpress 이미지 URL이 작동하지 않습니다.
<?php
$args = array('post_type' => 'product', 'posts_per_page' => 200, 'product_cat' => 'clothes');
$loop = new WP_Query($args);
$send_array = array();
while ($loop->have_posts()) : $loop->the_post();
global $product;
$send_array[] = array(
'id' => get_the_ID(),
'title' => get_the_title(),
'content' => get_the_content(),
'regular_price' => get_post_meta(get_the_ID(), '_regular_price', true),
'image' =>wp_get_attachment_image_src(),
'sale_price'=> get_post_meta(get_the_ID(), '_sale_price', true)
);
endwhile;
wp_reset_query();
ob_clean();
echo json_encode($send_array);
exit();
?>
이 코드는 올바르게 작동하고 데이터를 올바르게 출력합니다. 그러나 image
이 작동하지 않는 것 같습니다.
각 제품에 대한 이미지 URL을 가져오고 싶습니다. 위 코드에서 wp_get_attachment_image_src()
을 시도했지만 행운은 없습니다.
위의 코드를 사용하여 각 제품의 이미지 URL을 가져오고 값을 배열의 image
키에 배치하려면 어떻게해야합니까?
처럼 일 에이 매력. 또한 링크가 매우 도움이되었습니다. 매우 감사합니다. – Tester