From: Laury GvR Date: Wed, 17 May 2017 20:57:45 +0000 (-0400) Subject: Fixed the has-trail-product filter which was returning false too liberally, resulting... X-Git-Tag: v1.0.0^2~75 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=43c63004afdcf46fa5cb7e006b0fbd2831666bdb;p=WP-Themes%2Fmichigantrailmaps.git Fixed the has-trail-product filter which was returning false too liberally, resulting in the Buy Map button not to display on most products --- diff --git a/functions.php b/functions.php index 14dd004..0d604f6 100644 --- a/functions.php +++ b/functions.php @@ -272,30 +272,24 @@ add_filter('glm-get-trail-links', function($member_id) { }, 10, 2); add_filter('glm-has-trail-product', function($member_id) { - $products = get_posts( + wp_reset_query(); + $posts = get_posts( array( - 'post_status' => 'publish', - 'post_type' => 'product', + 'post_status' => 'publish', + 'post_type' => 'product', 'posts_per_page' => -1 -// 'meta_query' => array( -// array( -// 'key' => 'trail_id', -// 'value' => $member_id -// ) -// ) ) ); - foreach ($products as $product) { + foreach ($posts as $post) { // Explode the (hopefully) comma-separated list of member IDs into an array - $member_ids_for_product = explode(',', get_field( 'trail_id', $product->ID ) ); - + $member_ids_for_product = explode(',', get_field( 'trail_id', $post->ID ) ); + // If the current member is in the list of IDs if (in_array($member_id, $member_ids_for_product)) { return true; - } else { - return false; } } + return false; }); add_action('thematic_searchloop', 'mytheme_search_loop');