Sidebar events widget pulls region ID from function now
authorLaury GvR <laury@gaslightmedia.com>
Fri, 15 Feb 2019 23:19:12 +0000 (18:19 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Fri, 15 Feb 2019 23:19:12 +0000 (18:19 -0500)
functions.php
sections/county-page.php
sections/interior-page.php
sidebar.php

index 1deadc1..fd81833 100644 (file)
@@ -384,7 +384,27 @@ add_filter('events_search_widget', function(){
 //     10,
 //     2
 // );
-
+function get_members_region_id() {
+    global $post;
+    $membersRegionId = false;
+    if ( !isset($GLOBALS['glmDetailSlug']) || !$GLOBALS['glmDetailSlug'] ) {
+        // If not on a member detail page, and a region id custom field exists, use that as the id
+        if ( function_exists("get_field") && get_field('members_region_id',$post->ID) ) {
+            // Check current page's custom field
+            $membersRegionId = get_field('members_region_id',$post->ID);
+        } else if ( function_exists("get_field") && get_field( 'members_region_id', wp_get_post_parent_id( $post ) ) ) {
+            // Check parent's custom field
+            $membersRegionId = get_field( 'members_region_id', wp_get_post_parent_id( $post ) );
+        } else {
+             // If not on a member detail page, and no region id custom field exists, return events from all regions
+            $membersRegionId = false;
+        }
+    } else {
+        // If we're on a member detail page
+        $membersRegionId = apply_filters('get-current-memberinfo-field', 'region'); // returns null if no region found
+    }
+    return $membersRegionId;
+}
 function get_county_page_id() {
     global $post;
     $countyPageId = false;
index d0e7abe..7715352 100644 (file)
@@ -8,13 +8,7 @@
             <div id="county-content-expand-button">Show More</div>
         </div>
         <div class="small-12 large-4 columns county-landing-page-events-container" data-equalizer-watch>
-            <?php if ( function_exists("get_field") && get_field( "members_region_id" ) ) { ?>
-                <div class="row">
-                    <div class="small-12 columns">
-                        <?php $membersRegionId = get_field('members_region_id',$post->ID); ?>
-                    </div>
-                </div>
-            <?php } ?>
+            <?php $membersRegionId = get_members_region_id(); ?>
             <?php 
                 // Only show sidebar if memberRegion is set. 
                 // - INT val will show sidebar and show events for that region, occurs when on member detail and region is found
index 6e76253..cdbd3b8 100644 (file)
                 <div class="row">
                     <div class="small-12 large-8 columns" data-equalizer-watch>
                         <?php get_template_part('parts/main-content'); ?>
-                        <?php if ( $membersCategory && $membersCountyId) { ?>
-                            <?php // If this is a county child page ?>
-                            <br>
-                            <?php echo do_shortcode("[glm-members-list show='-map,-search' category='". $membersCategory ."' county-search='". $membersCountyId ."']"); ?>
-                        <?php } ?>
                     </div>
                     <div class="small-12 large-4 columns">
                         <?php get_sidebar(); ?>
index 8fa2c83..208a0f0 100644 (file)
         <?php } ?>
     <?php } else { ?>
         <?php
-            if ( !isset($GLOBALS['glmDetailSlug']) || !$GLOBALS['glmDetailSlug'] ) {
-                $memberRegion = false; // If not on a member detail page, return events from all regions
-            } else {
-                $memberRegion = apply_filters('get-current-memberinfo-field', 'region'); // returns null if no region found
-            }
+            $membersRegionId = get_members_region_id();
         ?>
         <?php 
             // Only show sidebar if memberRegion is set. 
             // - FALSE val will show sidebar and cause region flag to ignore, occurs when not on member detail (show events from all regions)
             // - NULL val will make sidebar events not show, occurs when we are on member detail but no region found
         ?>
-        <?php if ( isset($memberRegion) ) { ?>
+        <?php if ( isset($membersRegionId) ) { ?>
             <div id="sidebar-events">
                 <h2>Upcoming Events</h2>
-                <?php echo do_shortcode('[glm-members-event-list template="eventsFrontPageCity.html" region-search="'. $memberRegion .'" limit="3"]'); ?>
+                <?php echo do_shortcode('[glm-members-event-list template="eventsFrontPageCity.html" region-search="'. $membersRegionId .'" limit="3"]'); ?>
                 <a href="<?php echo get_permalink(757); ?>" class="button view-all-events">View All Events</a>
             </div>
         <?php } ?>