2016-06-01 8 views
0

私は、 "WP_Query"を使用してカスタム製品ループを作成して、Woocommerce製品データを表に表示し、正常に動作しています。しかし、'posts_per_page' => -1,は、サンプルカテゴリのすべての製品を表示していません。Woocommerceカスタム製品ループポストページ発行

現在、サンプルカテゴリには17の製品があります。その唯一の10の製品を示しています。 は私が問題をチェックし、「WP_Queryは」そう それは Setiingからページごとにポストの値を取っている記事で使用されていることを発見した>読み込み>ブログページが表示され、最大で

enter image description here

方法私は 'posts_per_page' => -1を作成して、Wordpress Postの1ページあたりの設定を変更せずに10以上の製品を使用することができます。ありがとうございました。 以下は私のフルコードです。

<?php // The args for the loop 
    $args = array(
     'posts_per_page' => -1, 
     'tax_query' => array(
      'relation' => 'AND', 
      array(
       'taxonomy' => 'product_cat', 
       'field' => 'slug', 
       'terms' => 'sample' // Your category name here 
      ) 
     ), 
     'post_type' => 'product', 
     'orderby' => 'title', 
    ); ?> 
    <?php 
     $loop = new WP_Query($args); // The Loop 
     if ($loop->have_posts()) { 
      while ($loop->have_posts()) : $loop->the_post(); ?> 
     <table> <!-- Fetching woocommerce data in table --> 
     <tr> 
      <td><?php the_content(); ?></td> <!-- Content --> 
      <td><?php the_title(); ?></td> <!-- Title --> 
      <td><?php echo ($sku = $product->get_sku()) ? $sku : __('N/A', 'woocommerce'); ?></td> <!-- SKU --> 
      <td><?php echo $product->get_price_html(); ?></td> <!-- Price --> 
      <td> 
      <?php global $product; // For Adding Add to Cart button in loop 
       echo apply_filters('woocommerce_loop_add_to_cart_link', 
       sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>', 
       esc_url($product->add_to_cart_url()), 
       esc_attr($product->id), 
       esc_attr($product->get_sku()), 
       $product->is_purchasable() ? 'add_to_cart_button' : '', 
       esc_attr($product->product_type), 
       esc_html($product->add_to_cart_text()) 
      ), $product); 
      ?> 
     </td> 
     </tr> 
     </table> 
     <?php 
      endwhile; 
     } else { 
      echo __('No products found'); 
     } 
     wp_reset_postdata(); 
    ?> 
+0

これが関連している:http://stackoverflow.com/questions/27395967/pagination-with-woocomerece-without-plugins/27405231#27405231 – LoicTheAztec

答えて

0

この

$maxposts = get_option('posts_per_page'); 
'posts_per_page' => $maxposts, 
+0

が機能していない、私が追加した$ maxposts = get_option( 'posts_per_page');変数の前に変数 'posts_per_page' => $ maxpostsを配列として格納します。 –

+0

この変数の中で値を取得しているかどうかをチェックする前に、この変数をループ開始前に 'echo $ maxposts;'してください。 – purvik7373

0

'posts_per_page' => -1, 

代わりに次のコードを使用してくださいしてみてくださいスニペット以下

add_filter('loop_shop_per_page', create_function('$cols', 'return 30;'), 20); 

リファレンス こと

関連する問題