Support

Account

Home Forums ACF PRO Displaying ACF fields with Post Connector plugin

Solved

Displaying ACF fields with Post Connector plugin

  • Howdy,

    I’m trying to use the Post Connector plugin (https://www.post-connector.com/) to form relationships between two different post types of mine. It works fine, until I try to introduce ACF fields into the mix.

    Has anyone here successfully displayed “child” post custom fields via Post Connector?

    Here’s the code I’m trying to get to work. It correctly creates the divs and lists for each child post, and displays their post title. However, it fails at displaying my repeater field.

    php
    <!-- Start Masonry Grid -->
    <div id="service-area__grid" class="masonry-grid">
    
        <?php /** Loop through the Service Areas **/
        $connected_post = Post_Connector::API()->get_children( "product-service-area", get_the_id() );
        if ( count( $connected_post ) > 0 ) :
    
            foreach ( $connected_post as $connected ) {
    
                echo '<div class="service-area__grid-item">';
    
                    // List Header
                    echo '<h5>' . $connected->post_title . '</h5>';
    
                    // Check if repeater field has rows with data
                    if( have_rows( 'sa_town_list' ) ) {
                        echo '<ul>';
                        // Loop through deez rowz (somethin came in da mail)
                        while( have_rows( 'sa_town_list' ) ) : $connected->the_row();
                            echo '<li>';
                                // Display the row
                                the_sub_field( 'sa_town_list_item' );
                            echo '</li>';
                        endwhile;
                        echo '</ul>';
                    } // end if
    
                echo '</div>'; // end grid-item
    
            } // end foreach
        endif; ?>
    
    </div> <!-- / Masonry Grid -->
    

    Thanks!!

  • Hi @steven

    I believe you can fix it by providing the ID of the child post as the second parameter of the have_rows() function. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/have_rows/. Also, I don’t think you need to use the $connected variable for the_row() function. Maybe something like this:

    if( have_rows( 'sa_town_list', $connected->ID ) ) {
        echo '<ul>';
        // Loop through deez rowz (somethin came in da mail)
        while( have_rows( 'sa_town_list', $connected->ID ) ) : the_row();

    I’m not sure how do you suppose to get the child post ID, so please change this code: $connected->ID with the right one.

    I hope this helps. Thanks!

  • Yes! It worked!!

    Thank you so much.

    Hopefully some day I’ll get to the point where I actually notice these small, almost obvious “mistakes” (calling for the child with no child ID). 🙂

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

The topic ‘Displaying ACF fields with Post Connector plugin’ is closed to new replies.