List Woocommerce Products on Sitemap Page

I have a nice sitemap page which dynamically lists all posts, all pages, and most importantly, all Woocommerce Products.

List Woocommerce Products on Sitemap Page

I once searched on the Internet on getting a list of all woocommerce products on a page but found nothing, some guys say we can use Shortcodes included with WooCommerce, but there is none that could match the goal – list all products through sitemap template file – sitemap.php or archive.php

After digging through some boring docs, I came across some code snippets that work.

woocommerce get list of all products via template file

Insert the core snippet below into sitemap template file at proper position:

                <?php $loop = new WP_Query( array( 
                    'post_type' => 'product', 
                    'posts_per_page' => 1000,
                    'orderby' => 'title',
                    'order'   => 'ASC'
                 ) ); ?>
                    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                        <li><?php the_title( '<a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a>' ); ?></li>
                    <?php endwhile; ?>

To understand it thoroughly, you need to study

Class Reference/WP Query- WordPres Codex

This entry was posted in WordPress. Bookmark the permalink.

One Response to List Woocommerce Products on Sitemap Page

  1. Tmu says:

    Jeriff. Why don’t you publish my comments? 🙁

Leave a Reply

Your email address will not be published. Required fields are marked *