In core WooCommerce, the pagination is added via the woocommerce_pagination()
function hooked to woocommerce_after_shop_loop
, and the sorting and result counts are output by the woocommerce_result_count()
and woocommerce_catalog_ordering()
functions. If you look at the source for these functions, you can see that they display according to the main $wp_query
, which will not contain any products because you’re querying posts with your own WP_Query.
So this might be one of those very rare occasions where query_posts()
would be the right thing to do. If you use query_posts()
in place of a secondary WP_Query, then those template functions should reflect your custom query.
ob_start();
query_posts( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );
if ( have_posts() ) : ?>
<?php do_action( 'woocommerce_before_shop_loop' ); //this would show post count and filter ?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php do_action( 'woocommerce_after_shop_loop' ); //this would show pagination ?>
<?php endif;?>
<?php
wp_reset_postdata();
wp_reset_query();
return '<div class="woocommerce columns-' . $column . '">' . ob_get_clean() . '</div>';
Take note of the wp_reset_query()
, that’s very important here.
I’m not sure pagination will work correctly though, you might need to use your own instance of paginate_links()
, refer to the documentation in the codex for examples of using paginate_links()
with a custom query.