mercredi 22 juin 2016

WooCommerce:Custom product template - Pagination isn't working

all products are displayed. "posts_per_page" is not working. I try to limit products to 12 by page, but it shows all products.

Looks like my code is fine, but it isn't working.

Whats wrong with my code?
Can someone enlighten me, please?

Here's my code:

<?php
    $meta_query   = array();
    $meta_query[] = array('key' => '_visibility','value' => array('visible', 'catalog'),'compare' => 'IN');
    $meta_query[] = array('key' => '_stock_status','value' => 'instock','compare' => '=');
    if($min_price !='' && $max_price !=''){
        $meta_query[] = array('key' => '_price','value' => array($min_price, $max_price),'compare' => 'BETWEEN','type' => 'NUMERIC');
    }
    if($orderbym != '')
    {
      $mkey = '_price';
    }
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $query_args = array(
        'post_type'           => 'product',
        'post_status'         => 'publish',
        'posts_per_page'      => 10,
        'paged'               => $paged,
        'ignore_sticky_posts' => 1,
        'orderby'             => $orderby,
        'order'               => $order,
        'posts_per_page'      => -1,
        'meta_query'          => $meta_query,
        'meta_key'            => $mkey,
        'tax_query'           => array(
            array(
              'taxonomy'      => 'product_type',
              'field'         => 'slug',
              'terms'         => 'bundle',
            ),
            $product_catar
        ),
    );
    global $woocommerce_loop;
    $products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $query_args));
    $columns   = '2';
    $woocommerce_loop['columns'] = $columns;
    ob_start();
    if($products->have_posts()){
      woocommerce_product_loop_start();
      while ( $products->have_posts() ) {
          $products->the_post();
          wc_get_template_part( 'content', 'product' );
      }
      woocommerce_product_loop_end();
   }else{
      _e( 'No product matching your criteria.' );
   }
   woocommerce_reset_loop();
   wp_reset_postdata();
   echo '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
?>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire