Home › Forums › Front-end Issues › Advanced Custom Fields – Meta Query no result › Reply To: Advanced Custom Fields – Meta Query no result
Your code looks correct, however, query_posts
is used to modify the main query of the post/page you’re on. You’ll probably want to use get_posts
instead. The rest remains the same:
$args = array(
'post_type' => 'post',
'cat' => 399,
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'organization_type',
'value' => 'socialbusiness',
)
)
);
?>
<?php
$social_businesses = get_posts( $args );
if ( $social_businesses ): ?>
<?php foreach ( $social_businesses as $sb ): ?>
<a href="<?php echo get_permalink( $sb->ID ); ?>"><?php echo get_the_title( $sb->ID ); ?></a><br>
<?php endforeach; ?>
<?php endif; ?>
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.