From d86b5924e8466406a9ae235c8af5d777e6e5be07 Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Wed, 22 Feb 2017 10:24:14 -0500 Subject: [PATCH] Added a meta_query to filter the frontpage products by visibility --- parts/shop-cats-and-products.php | 8 ++++++++ sections/front-page.php | 32 ++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/parts/shop-cats-and-products.php b/parts/shop-cats-and-products.php index e7fc0c8..3c8e0d8 100644 --- a/parts/shop-cats-and-products.php +++ b/parts/shop-cats-and-products.php @@ -22,8 +22,16 @@ ) ), '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()) { ?> diff --git a/sections/front-page.php b/sections/front-page.php index 2131578..a7b1ace 100644 --- a/sections/front-page.php +++ b/sections/front-page.php @@ -60,18 +60,26 @@ ' . $product_category->name . ''; $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 "