I’m also having an issue with this using 4.4. It definitely worked with 4.2, not sure if something change in 4.4 or maybe 4.3
Had to tweak it some, something about the compare “like” wasn’t working. This seems to work…
$args = array(
'post_type' => 'event',
'meta_query' => array(
array(
'key' => 'business_name',
'value' => get_the_ID()
)
)
);
Thanks!
Matt
Yes it was outputting an empty list or nothing? Hard to tell…
That code outputs “Array ()”
Thanks,
Matt
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; ?>
That worked thanks! Just added
'orderby' => array(
'event_date' => 'ASC',
'time_start' => 'ASC'
),
Matt
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.