반응형
wp_query woocmerce를 사용하여 베스트셀러 상품을 얻는 방법
홈페이지에서 베스트셀러 제품을 구매하고 싶습니다.Below query를 사용하고 있습니다만, 모든 카테고리에서 베스트셀러 제품을 얻는 것은 아닙니다.
베스트셀링 상품 숏코드를 넣었는데 작동은 되는데 커스텀 구조로는 그 상품들을 받을 수가 없었습니다.이러한 내 쿼리 함수..
function get_product_posts_hp()
{
wp_reset_query();
$args = array(
'posts_per_page' => 12,
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
return new WP_Query($args);
}
Thanks In Advance..
당신의 코드는 전세계적으로 작동합니다.다음 기능 코드로 시도해 보았습니다.
function get_product_posts_hp(){
$query = new WP_Query( array(
'posts_per_page' => 12,
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
'order' => 'DESC',
) );
echo '<p>Count: '. $query->post_count ; '</p>';
if($query->have_posts()) :
while($query->have_posts()) : $query->the_post();
echo '<p>' . get_the_title() . ' (';
echo get_post_meta( get_the_id(), 'total_sales', true) . ')</p>';
endwhile;
wp_reset_postdata();
endif;
}
그리고 총 매출 DESC별로 12개의 상품 타이틀이 표시됩니다.
언급URL : https://stackoverflow.com/questions/52217639/how-to-get-best-selling-products-using-wp-query-woocommerce
반응형
'programing' 카테고리의 다른 글
파싱하는 방법Int in Angular.js (0) | 2023.10.09 |
---|---|
MariaDB. 연결 재사용 (0) | 2023.10.09 |
자바스크립트에서 고투를 어떻게 사용할 수 있습니까? (0) | 2023.10.09 |
Spring Boot 테스트 클래스에서 @WebMvcTest 주석을 사용할 때 오류가 발생했습니다. (0) | 2023.10.09 |
임의 값으로 배열 만들기 (0) | 2023.10.09 |