Support

Account

Home Forums Add-ons Repeater Field ACF Repeater Display row fields if field_name = page_name

Solved

ACF Repeater Display row fields if field_name = page_name

  • I’ve use Advanced Custom Fields to fill in contact details for 6 Schools – which all show on the Contact page.

    Each school has a course page and I would like to display those contact details on the course page for that school.

    I need school A’s contact details to show on the “Courses at school A” page. The course page name “School A” is identical to the get_sub_field(‘school_name’).

        <?php if(have_rows('schools', 45) ): ?> // 45 is post ID in WP
        <?php  while (have_rows('schools', 45) ): the_row(); 
    
        // vars
        $pagetitle = get_the_title(); // get page title in WP
        $school = get_sub_field('school_name'); // get school name
    
        if ($school == $pagetitle){ // IF they are the same THEN
        ?> 
    
        <article class="school-contacts">
        <ul class="contact-info">
            <li><strong><?php echo $school; ?></strong></li>
    //other fields omitted for clarity
           </ul> 
        </article> 
        <?php } ?>
        <?php endwhile; endif; ?>

    My problem is that ALL the schools show up when I do this.

    I need to find a way so that only School A shows up on School A page, School B on School B page etc.

    I’ve added in some checks (removed from this code for clarity) but they show that School = School A Pagetitle = School A So the matching is working correctly.

    I’m just stuck on how I can get the ACF output to ONLY show school A.

  • Solved:

    if ($school == $pagetitle)

    needed to be

    if ($school == $pagetitle) : the_row();

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF Repeater Display row fields if field_name = page_name’ is closed to new replies.