Support

Account

Home Forums Add-ons Repeater Field Accessing Repeater Field from another page

Solved

Accessing Repeater Field from another page

  • I hope I am not creating a thread that has been used before.

    I have a site that has a homepage and a services page. The services page has ACF Field group called Services and a repeater field called Service. They display perfectly on the Services page however I want to also display them on the homepage.

    I have tried doing

    
    <?php
    if( have_rows('service', 'services') ):
    
    	while( have_rows('service', 'services') ): the_row();
    	
    		$service_title = get_sub_field('service_title');
    		$service_short_text = get_sub_field('service_short_text');
    		$service_graphic = get_sub_field('service_graphic');
    		$service_link = get_sub_field('service_link');
    		$service_display = get_sub_field('service_display');
    		
    		// I output these variables in the loop here
    		echo $service_title;
    		
    		// And others go below
    	
    	endwhile;
    					
    endif; 
    ?>
    
    

    Nothing shows up.

    Any ideas? It is probably straight forward but am starting to feel stooopid here.

    Thanks in advance.

    Muz

  • Okay. Worked it out.

    I needed to change

    if( have_rows('service', 'services') ):
    while( have_rows('service', 'services') ): the_row();
    

    to

    if(get_field('service', 7)):
    while(has_sub_field('service', 7)):
    

    the second variable needs to be the post id not the page name.

    Found the code on the ACF documentation.
    http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-another-page/

    Under the heading: Working with the Repeater Field.

    I thought I had read the page all the way through.
    Hope it helps others.

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

The topic ‘Accessing Repeater Field from another page’ is closed to new replies.