Support

Account

Home Forums Add-ons Repeater Field Page Link field in a repeater?

Helping

Page Link field in a repeater?

  • I have created a repeater field where the repeated element is a page link field.

    I’m not sure of the syntax for getting the link name and url of each link. I know how to loop through a repeater, but not the syntax for the page link. For example:

    <?php if( get_field('related_assets') ): ?>
    		<ul>
    		<?php while( has_sub_field('related_assets') ): the_row();
    		$related = get_sub_field('related_asset');
    		?>
    		<li><?= $related; ?></li>
    		<?php endwhile; ?>
    		</ul>
    <?php endif; ?>

    Which gets me:

    /design_asset/movable-panel/
    /design_asset/tabbed-section/

    The links are correct, but how to get the label (what was displayed in the link menu in the editor mode)?

  • Hi @smlombardi

    The page link field will only return the url to the post, not it’s title.

    It is possible to get the raw page link value which is a post ID.
    You can do this by adding an extra ‘false’ param to your get_sub_field function.

    With the ID, you can load both the URL and the title via PW functions such as:
    get_permalink()
    get_the_title()

    Resources:
    http://www.advancedcustomfields.com/resources/page-link/
    http://www.advancedcustomfields.com/resources/get_sub_field/

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

You must be logged in to reply to this topic.