Support

Account

Home Forums Front-end Issues Multiple loops comparing meta value problem Reply To: Multiple loops comparing meta value problem

  • Hey. Thanks for your answer. There is definitely more to the story, but I thought it would be a lot to post and possibly irrelevant. I’m not using setup_postdata. Here is the full code for loop-events.php

    (I’m using if_single so that I can just load the same loops using get_template_part, but the same problem occurs if I copy the whole loop into the single page)

    <div id="event-archive" class="clearfix">
    
    <?php if (is_single()) { $uargs = array(       'post_type' => 'events',
    	'posts_per_page' => 3,
    	'meta_key' => 'eventdate', // name of custom field
    	'orderby' => 'eventdate',
    	'order' => 'ASC',
    	'meta_query' => array(
    								array(
    									'key' => 'attending', // name of custom field
    									'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    									'compare' => 'LIKE'
    								)
    							)
    							
    							 ); ?>
    
    <?php 					 
    } else {
    $uargs = array (
     'post_type' => 'events',
    	'posts_per_page' => -1,
    	'meta_key' => 'eventdate', // name of custom field
    	'orderby' => 'meta_value_num',
    	'order' => 'ASC'
    	
    );
    
    }
    
    $uloop = new WP_Query( $uargs ); ?>
     
    
     
    <?php while ( $uloop->have_posts() ) : $uloop->the_post();
    
    ?>
    
    <?php
    
    $date = get_field('eventdate');
    // $date = 19881123 (23/11/1988)
     
    // extract Y,M,D
    $y = substr($date, 0, 4);
    $m = substr($date, 4, 2);
    $d = substr($date, 6, 2);
     
    // create UNIX
    $time = strtotime("{$d}-{$m}-{$y}");
    
     ?>
     
     
                    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    
                    <div id="event-1" class="event">
    <div id="event_datestamp"><p class="hdm"><?php echo date('M', $time); ?></p><p class="hdd"><?php echo date('d', $time); ?></p></div>
    			
                <?php $eurl = get_field('eventurl'); ?>
    
    			<h2 class="event-title"><a href="<?php echo get_permalink($eurl->ID); ?>" title="<?php printf( esc_attr__( 'Read about this event', 'wpzoom' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                
                
                
     <span class="att-artists">	         
    
    <?php 
     
    $posts = get_field('attending');
     $i = 0;
     
    if( $posts ):  ?>
    
         
        <?php 
    
    	 foreach( $posts as $p ): ?>
         
            <?php 
    		
    		$i++;
    		
    		 ?>
             
            <?php 
    			
    	
    			if( $i == 1 )
    		{
    			echo '';
    		}
    		elseif( $i == count($posts) )
    		{
    			echo ', ';
    		}
    		elseif( $i > 1 )
    		{
    			echo ', ';
    		}
    		
      ?>
           
                <a href="<?php echo get_permalink( $p->ID ); ?>" title="See <?php echo get_the_title( $p->ID ). '’s profile'; ?>"><?php echo get_the_title( $p->ID ); ?></a>
                
               
              
            
    		<?php endforeach; ?>
        	<?php endif; ?></span></div>
                
                <div id="event-2" class="event"><div class="eventmeta"><span class="event-meta1"><?php the_field('eventloc'); ?></span>
                <span class="event-meta2"><?php echo date('d/m/Y', $time) . ' ('; the_field('age'); echo ')'; ?></span>
                </div></div>
                <div id="event-3" class="event"><div id="gettick"><span class="event-tkt"><a href="<?php the_field('biturl'); ?>" target="_blank">Book Now</a></span></div></div>
    	
                    </div>
    
     
    <?php 
    
    endwhile;
     ?>
    
     </div>

    All my loops work fine individually on the single-artist page, and on their individual archive pages. But this, for some reason, can only work once:

    'meta_query' => array(
    								array(
    									'key' => 'attending', // name of custom field
    									'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    									'compare' => 'LIKE'
    								)
    							)

    The fields are correct and I’ve checked so that there are no mistakes with variables etc.