Support

Account

Home Forums Front-end Issues query based on current page Reply To: query based on current page

  • I tried to copy what was on the page you linked but it still doesn’t return any events, just blank. The first “business” loop still works but there are no events displayed. Below is the full code.

    
    <?php while ( have_posts() ) : the_post(); ?>
    					
            <div class="large-12 medium-12 small-12 columns">
    		<h1><?php the_title( ); ?></h1> 
    	</div>
    						
    	<div class="large-9 medium-9 small-9 columns">
    		<ul class="large-block-grid-2 medium-block-grid-2">
    			<li>
    				<h6>
    				<a>"><?php the_field( 'business_website' ); ?></a>
    				</h6>
    			</li>
    			<li>
    				<h6>
    				<a>"><?php the_field( 'business_phone' ); ?></a>
    				</h6>
    			</li>
    		</ul>
    	</div>
    						
    	<?php 
    
    	$location = get_field('business_map');
    							
    	if( !empty($location) ):
            ?>
    		<div class="acf-map">
    		<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
    		</div>
    
    	<?php endif; ?>
    				
    	<?php
    			
    	$business_event = get_posts(array(
    		'post_type' => 'event',
    		'orderby'    => array(
    			'event_date' => 'ASC',
    			'time_start' => 'ASC'
    			),
    		'meta_query' => array(
    			array(
    			'key' => 'business_name', // name of custom field
    			'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    			'compare' => 'LIKE'
    			)
    		)
    		));
    	?>
    		
    	<?php if( $business_event ): ?>
    		
    		<ul class="large-block-grid-2 medium-block-grid-2">
    									
    		<?php foreach( $business_event as $business_event ): ?>
    										
    			<li>
    						
    				<?php include("event.php"); ?>
    						
    			</li>	
    												
    		<?php endforeach; ?>
    								
    		</ul>
    									
    	<?php endif; ?>
    												
    <?php endwhile; ?>