Home › Forums › General Issues › 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>
You must be logged in to reply to this topic.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.