Home Forums Add-ons Repeater Field How to get title for multiple links(PageLink)


How to get title for multiple links(PageLink)

  • Hello, this is my first post here(:

    From the code below, You can see that I have Repeater with subfields.
    Everything works as expected, only one part gives me headache.

    Subfield(link) is “Page Link” with “Select multiple values” option selected, so I could add multiple links and it works fine for both languages ( and so on.. )

    For two days now I’m trying to get post tilte for each link instead of url without any luck :/

    if ( have_rows( 'repeater_field' ) ): ?>
    <div class="grid">
      <div class="grid-sizer"></div>
      <?php while( have_rows('repeater_field') ): the_row(); 
    // vars
    $image = get_sub_field('photo');
    $content = get_sub_field('description');
    $links = get_sub_field('link');
      <article id="post-<?php the_ID(); ?>" class="grid-item <?php the_sub_field('photo_size_class'); ?>">
        <div class="blog-image">
          <img src="<?php echo $image['url']; ?>" class="img-responsive" alt="<?php echo $image['title'] ?>"/>
        <div class="content">
          <p class="description">
    // vars
    // check 
    if( $links ): ?>
            <?php foreach( $links as $link ): ?>
            <a href="<?php echo $link ?>">
              <?php echo get_the_title($link); ?>
            <?php endforeach; ?>
            <?php endif; ?>
                <!-- End for each -->
            <?php echo $content; ?>
          <!-- .entry-content -->
      <!-- #post-## -->
      <?php endwhile; ?>
  • the “Page Link” field only returns URLs. get_the_title() requires a Post ID as input. You could possibly use this to get the Post ID, however, the page link field also lets you select archive pages and there is no way in WP to convert these URLs or get the title of the page. The page link field was not really designed to do what you’re trying to do. The Post Object field, or relationship field might be a better choice.

  • Thank You, John. I’ve solved this by changing “Page Link” to “Relationship” and paste my code directly in to my page template(page-ID.php).

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

You must be logged in to reply to this topic.