Support

Account

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; ?>