// Add a custom shortcode to display products function procter_product_shortcode($atts) { $atts = shortcode_atts(array( ‘category’ => ‘default’, ), $atts); // Query products based on category $args = array( ‘post_type’ => ‘product’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => $atts[‘category’], ), ), ); $products = new WP_Query($args); // Output product list if ($products->have_posts()) { $output = ‘<div class=”procter-products”>’; while ($products->have_posts()) { $products->the_post(); $output .= ‘<div class=”product-item”>’; $output .= ‘<h3>’ . get_the_title() . ‘</h3>’; $output .= ‘<p>’ . get_the_excerpt() . ‘</p>’; $output .= ‘</div>’; } $output .= ‘</div>’; } else { $output = ‘<p>No products found.</p>’; } wp_reset_postdata(); return $output; } add_shortcode(‘procter_products’, ‘procter_product_shortcode’);