Fixed the has-trail-product filter which was returning false too liberally, resulting...
authorLaury GvR <laury@gaslightmedia.com>
Wed, 17 May 2017 20:57:45 +0000 (16:57 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Wed, 17 May 2017 20:57:45 +0000 (16:57 -0400)
functions.php

index 14dd004..0d604f6 100644 (file)
@@ -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');