Title: [Plugin: Advanced Custom Fields] Problem with multiple loops comparing meta val
Last modified: August 21, 2016

---

# [Plugin: Advanced Custom Fields] Problem with multiple loops comparing meta val

 *  [pierredst](https://wordpress.org/support/users/pierredst/)
 * (@pierredst)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/plugin-advanced-custom-fields-problem-with-multiple-loops-comparing-meta-val/)
 * Hi.
 * I’m using the plugin Advanced Custom Fields. I have two different post types,
   called “events” and “release”. Both has a relationship field where you can pick
   artists from my third post type called “artist”.
 * In the single post for a specific artist, I’m trying to loop the events and releases
   from the artist.
 * In single-artist.php, I’m loading the loop templates:
 *     ```
       <?php get_template_part( 'loop', 'events' ); ?>
   
               <?php get_template_part( 'loop', 'release' ); ?>
       ```
   
 * Below is the query that matches the artist ID. It works just fine, but only ONCE!
   The query is pretty much the same on events and releases, but only the “get_template_part
   loop” I place above the other works. So if the events is on top, I see the artists
   events. If the releases are on top, I see the artists releases. But never both.
 *     ```
       <?php 
   
       if (is_single()) {
   
       $args = array( 'post_type' => 'release', 'posts_per_page' => -1, 
   
       	'meta_query' => array(
       								array(
       									'key' => 'artist-name', // name of custom field
       									'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
       									'compare' => 'LIKE'
       								)
       							)
       				); ?>
   
                       <?php } else { 
   
       				$args = array( 'post_type' => 'release', 'posts_per_page' => -1);
   
       				}?>
       ```
   
 * I hope I explained it good enough, and hopefully someone can give me an answer
   to why the query only works the first time.

The topic ‘[Plugin: Advanced Custom Fields] Problem with multiple loops comparing
meta val’ is closed to new replies.

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)
 * [multiple loops](https://wordpress.org/support/topic-tag/multiple-loops/)
 * [Relationship](https://wordpress.org/support/topic-tag/relationship/)

 * 0 replies
 * 1 participant
 * Last reply from: [pierredst](https://wordpress.org/support/users/pierredst/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/plugin-advanced-custom-fields-problem-with-multiple-loops-comparing-meta-val/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
