Support

Account

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.