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


Repeater field – only show row with relationship to page

    • jlock

    • March 21, 2020 at 12:42 am

    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.

    • jlock

    • March 23, 2020 at 5:06 am

    Awesome… it works!

    Thank you very much

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

You must be logged in to reply to this topic.

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.