Home Forums Add-ons Repeater Field Repeater field – only show row with relationship to page


Repeater field – only show row with relationship to page

  • I have a posttype which shows employees. The employees are shown on different pages and need to have a specific content text for each separate page. For this I have created a repeater with a text field and relationship field in which I select the page.

    I have made a while regular while loop with an if condition to try only and show the row related to the page id, but it loops out all rows.

    $page_id = get_queried_object_id();
    if( have_rows('employee_subject_description') ):
        while ( have_rows('employee_subject_description') ) : the_row();
             $employee_subject_description_content = get_sub_field('employee_subject_description_content');
             $employee_subject_description_subject = get_sub_field('employee_subject_description_subject');
            if ( $page_id = $employee_subject_description_subject->ID ){
                $excerpt .= '<div class="employee_subject_content>' . get_sub_field('employee_subject_description_content') . '</div>';
    else :
        // no rows found

    Anyone who can help with this?

  • The = in if ( $page_id = $employee_subject_description_subject->ID ) should be changed to === to compare that the two values are equal. Your single = is actually assigning the value of $employee_subject_description_subject->ID to the $page_id variable.

  • Awesome… it works!

    Thank you very much

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

The topic ‘Repeater field – only show row with relationship to page’ is closed to new replies.