Home › Forums › Front-end Issues › Trying to compare post title with repeater field › Reply To: Trying to compare post title with repeater field
Ok, so I finally figured it out. It turns out I was over complicating it as usual. I will post my solution in case it helps others. I was trying to put together a complicated compare loop where I compare a post object field that sits in a repeater from another post type with the title of the current post and then loop if they matched.
Anyway, here is what I ended up with:
<?php
$post_id = get_the_title();
$wp_query = new WP_Query();
$wp_query->query( array (
'post_type' => 'case',
));
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php while ( have_rows('shift_details') ) : the_row(); ?>
<?php $post_object = get_sub_field('nurse'); if( $post_object ) : $post = $post_object; setup_postdata($post); ?>
<?php $nurse_title = get_the_title(); ?>
<?php if ($nurse_title == $post_id) { ?>
<?php wp_reset_postdata(); ?>
So, I am actually just querying the post type and then looping through all repeater rows but then adding a check to see if they match after and continuing the loop if they do. I hope this makes sense and helps someone else out there.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.