Show all product titles

Snippet to show a list of all products in WooCommerce. Place in functions.php, next browse to YOURDOMAIN.nl?show_all_products

add_filter('the_content', 'sw_the_content');
function sw_the_content($content)
{

    if (isset($_GET['show_all_products'])) {
        $query_args = array(
            'post_type' => 'product',
            'posts_per_page' => -1,
            'orderby' => 'title',
            'order'   => 'ASC',
        );

        // The Query
        $the_query = new WP_Query($query_args);

        // The Loop
        if ($the_query->have_posts()) {
            while ($the_query->have_posts()) {
                $the_query->the_post();
                echo the_title();
                echo '<br>';
            }
            /* Restore original Post Data */
            wp_reset_postdata();
        } else {
            // no posts found
        }
    }
    return $content;
}

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest
Author picture

SitiWeb is de expert op het gebied van WordPress. gespecialiseerd in het leveren van maatwerk.

Leave a comment

Geef een reactie

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *