Woocommerce の商品カテゴリ
/* データの表示指定 */
$type =15;  // カテゴリID 
$item_count = 6; //1ページに表示したいアイテム数 
$sp = empty($_GET['pg']) ? 1 : $_GET['pg'] ;
$field = "SELECT object_id , p.post_title ,post_content,post_date,post_excerpt,post_name,
p.post_type , p.post_status, m.stock_quantity , m.min_price, m.max_price ,meta_value" ;
$query = "
FROM `$wpdb->term_relationships` as t
left join $wpdb->posts as p on p.id = t.object_id 
left join `$wpdb->wc_product_meta_lookup` as m on m.product_id = t.object_id 
left join `$wpdb->postmeta` as e on e.post_id = t.object_id 
WHERE `term_taxonomy_id` = %d AND p.post_type = 'product' AND p.post_status = 'publish' 
AND e.meta_key = '_price' " ;
$sql = $field . $query ." LIMIT %d, $item_count;";
$results = $wpdb->get_results( $wpdb->prepare( $sql ,$type ,($sp-1)*$item_count) );
foreach($results as $row) var_dump($row);
[/highlight_php]
このページのページャー
[highlight_php]
<?php    /* 以下、ページャーの表示 */
$field = "SELECT count(*) ";
$sql = $field . $query ;
$product_count = $wpdb->get_var( $wpdb->prepare( $sql , $type) );
$product_page = ceil( $product_count/$item_count); //ページ数
?>
<nav class="undernav pagination">
<?php
   if( $sp > 1){
      echo '‹ 前へ ';
   } 
?>
   Page =$sp?> of =$product_page?>
 <?php
   for( $i=1 ; $i <= $product_page; $i++){
      if( $i == $sp ){
         echo '';
      }else{
         echo '';
      }
   }
   if( $sp < $product_page){
      echo '次へ ›';
   } 
 ?>