Home Forums ACF PRO Using object from repeater


Using object from repeater

  • Hello,
    I have two Custom Post Types

    • Buildings
    • Apartments

    They are connected thru Post Object. Apartment have field where i choose Building, and i can extract some data like ->

        $ligging = get_field('project_for_apartment');
        <?php the_field('location_facility', $ligging->ID) ?>

    With that code i extract location from Project page to apartment. That works without any error. But when i try to extract data from repeater field on project page i dont get any results. How can i extract data from fields in repeater (on another page)

    Thank you a lot !

  • Hi @mitrovics

    I’m afraid I don’t understand your field group structure. Could you please share the JSON or XML export of the field group and some screenshots of the issue?


  • In basic its simple Apartment CPT have targeted field group called Projects for Apartment. That field group is set for POst Object and restricted to Projects CTP. Then i have field in repeater Location Facility that targets Projects CTP. So i create for example post under Projects with filled informations for location and i display that data on single-projects.php page. But i want to display that same data on single-apartment.php . When i try to extract data from normal field its ok, but i dont know how to extract field from repeater.

  • Ok let me explain better because i am real stuck here. I have custom post type Projects (buildings), and i have custom post type Apartments. How can i assign some specific apartments to belong to some projects. For example i have Project 1, Project 2, and i have Apartment 1 and Apartment 2. How can i create relationship between those , i want to asign Apartment 2 to Project 1. Then i want to display on apartment-single.php some data from project 1 like location, features etc.

  • Hi @mitrovics

    So, from the Apartment2 page, you want to get the custom field of the Project1?

    If you can get the ID of the Poject1 post, you can pass it to the get_field() function as the second parameter like this:

    $post_id = 99; // change it with the ID of Project1 post
    get_field('custom_field_name', $post_id);

    This page should give you more idea about it:

    You can also do it with a repeater like this:

    have_rows('repeater_field_name', $post_id);

    This page should give you more idea about it:

    If this is not the issue, I believe sharing the export file and screenshots of the issue would explain the situation better.


  • Its working when i target specific ID but i have doze of posts i cant just add id by id, corect ? Can i target all posts for example from certain Custom Post Type?

  • Hi @mitrovics

    I’m still not sure about the setup of your custom fields, so forgive me if I’m wrong. I believe you can get the id using something like this:

    $ligging_id = get_field('project_for_apartment', false, false);

    I hope this helps.

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

The topic ‘Using object from repeater’ is closed to new replies.