4.0Essential Grid 4.0 is here — see what’s new

FAQ

Auto-populate WooCommerce Category page with Essential Grid

Essential Grid 3 · The 4.0 FAQ

The following code snippet can be used to auto-populate a grid for your WooCommerce product category pages.

The code below can be added to one of your WooCommerce page templates, such as “archive-product.php”.

<?php

    $ids = array();
    $cat = get_query_var('product_cat');
    $args = array( 'post_type' => 'product', 'product_cat' => $cat );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product;

        $ids[] = $loop->post->ID;

    endwhile;
    wp_reset_query();

    // replace "my-grid" with the alias name from one of your grids
    echo do_shortcode('[ess_grid alias="my-grid" posts="'.implode(',', $ids).'"]');

?>
Black Friday

30% off your first year of Essential GridBlack Friday: 30% off Until Ends tonight

See the offer