Added a meta_query to filter the frontpage products by visibility
authorLaury GvR <laury@gaslightmedia.com>
Wed, 22 Feb 2017 15:24:14 +0000 (10:24 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Wed, 22 Feb 2017 15:24:14 +0000 (10:24 -0500)
parts/shop-cats-and-products.php
sections/front-page.php

index e7fc0c8..3c8e0d8 100644 (file)
                     )
                 ),
                 'post_type' => 'product',
+                'post_status' => 'publish',
                 'orderby' => 'menu_order',
                 'order' => 'ASC',
+                'meta_query' => array(
+                    array(
+                        'key'       => '_visibility',
+                        'value'     => 'hidden',
+                        'compare'   => '!=',
+                    )
+                )
             );
             $products = new WP_Query( $args );
             if ($products->have_posts()) { ?>
index 2131578..a7b1ace 100644 (file)
                             <?php 
                             echo '<h4><a href="' . get_term_link( $product_category ) . '">' . $product_category->name . '</a></h4>';
                             $args = array(
-                                 'posts_per_page' => -1,
-                                 'tax_query' => array(
-                                     'relation' => 'AND',
-                                     array(
-                                         'taxonomy' => 'product_cat',
-                                         'field' => 'slug',
-                                         'terms' => $product_category->slug
-                                     )
-                                 ),
-                                 'post_type' => 'product',
-                                 'orderby' => 'menu_order',
-                                 'order' => 'ASC'
+                                'posts_per_page' => -1,
+                                'tax_query' => array(
+                                    'relation' => 'AND',
+                                    array(
+                                        'taxonomy' => 'product_cat',
+                                        'field' => 'slug',
+                                        'terms' => $product_category->slug
+                                    )
+                                ),
+                                'post_type' => 'product',
+                                'post_status' => 'publish',
+                                'orderby' => 'menu_order',
+                                'order' => 'ASC',
+                                'meta_query' => array(
+                                    array(
+                                        'key'       => '_visibility',
+                                        'value'     => 'hidden',
+                                        'compare'   => '!=',
+                                    )
+                                )
                             );
                             $products = new WP_Query( $args );
                             echo "<ul>";