Support

Account

Home Forums General Issues Query posts by repeater sub-field

Helping

Query posts by repeater sub-field

  • Hi –
    This summer I added a feature on a website I built for a theatre company. On the Production Pages, artists (custom post type) were added and given roles. Then on the artist profile pages, it would dynamically populate a table with all productions that artist was attached to along with their role. I read the documentation posted on this site and it worked great. However, last month this feature mysteriously stopped working! Any thoughts on what may have changed? Any thoughts at all would be welcome!

    Thanks

    		<table>
    		
    			<tr>
    
    				<th>Production</th>
    
    				<th>Role</th>
    
    			</tr>
    
    			<tr>		
    
    		<?php
    
    			// filter for cast
    
    			function my_posts_where( $where ) {
    
    				$where = str_replace("meta_key = 'production_company_%", "meta_key LIKE 'production_company_%", $where);
    
    				return $where;
    
    			}
    
    			// filter for creative
    
    			function my_posts_where2( $where2 ) {
    
    				$where2 = str_replace("meta_key = 'creative_team_%", "meta_key LIKE 'creative_team_%", $where2);
    
    				return $where2;
    
    			}
    
    		$thisGuy = get_the_ID();
    
    			add_filter('posts_where', 'my_posts_where');
    
    			add_filter('posts_where', 'my_posts_where2');
    
    						$productions = get_posts(array (
    
    							'suppress_filters' => FALSE,
    
    							'post_type' => 'production',
    
    							'numberposts' => -1,
    
    							'meta_query' => array (
    
    								'relation' => 'OR',
    
    								array(
    
    									'key' => 'production_company_%_cast_name',
    
    									'value' => '"' . get_the_ID() . '"',
    
    									'compare' => 'LIKE'
    
    									),
    
    								array(
    
    									'key' => 'creative_team_%_creative_name',
    
    									'value' => '"' . get_the_ID() . '"',
    
    									'compare' => 'LIKE'
    
    						))
    
    						));
    
    		 $the_query = new WP_Query( $productions );
    
    	      if($productions): foreach($productions as $production):
    
    				  ?>
    
    		<td class="playTitle">
    
    			<a href="<?php the_permalink($production->ID); ?>"><?php echo get_the_title($production->ID); ?></a> 
    
    		</td>
    
    		<td>
    
    		<?php
    
    			$people = get_field('production_company', $production->ID);
    
    			$creatives = get_field('creative_team', $production->ID);
    
    			if($people):
    
    				foreach($people as $person):
    
    					$artists = $person['cast_name'];
    
    					$hisRole = $person['cast_role'];
    
    						if($artists):
    
    							foreach($artists as $artist):
    
    								$myGuy = get_the_title($artist->ID); 
    
    							endforeach;
    
    							if($myGuy == get_the_title($thisGuy)):
    
    								echo '<div>' . $hisRole . '</div>'; 
    
    							endif; 
    
    						endif;
    
    				endforeach;  
    
    			endif;
    
    			
    
    			if($creatives):
    
    				foreach($creatives as $create):
    
    				$designers = $create['creative_name'];
    
    				$position = $create['creative_role'];
    
    					if($designers):
    
    						foreach($designers as $designer):
    
    							$myGal = get_the_title($designer->ID);
    
    						endforeach;
    
    						if($myGal == get_the_title($thisGuy)):
    
    							echo '<div>' . $position . '</div>';
    
    						endif;
    
    					endif;
    
    				endforeach;
    
    			endif;
    
    		?>
    
    		</td>	</tr>	  
    
    				  <?php endforeach; endif; ?>	</table>
    
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Query posts by repeater sub-field’ is closed to new replies.