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; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.