Home Forums Front-end Issues Page Link fails when cloned (Clone Field)


Page Link fails when cloned (Clone Field)

  • When cloning a Page Link field, it returns only the page ID, rather than the actual page url.

    For example:

    $button = get_field('header_button');
    if($button): ?>
      <a href="<?php echo $button['link']; ?>"><?php echo $button['label']; ?></a>
    <?php endif; ?>

    $button['link'] returns a numerical page ID rather than a url.

    ACF V5.4.8
    WP V4.6.1

  • Submit a new support ticket for this It’s the fastest way to get it to the developer.

  • This is definitely happening (and still happening – ACF V5.5.3, WP V4.7).

    dkeeling – a workaround is to check if the value is numeric, and then run it through get_permalink() if it is.

    Your code would look like this:

    $button = get_field('header_button');
    if($button): ?>
      <a href="<?php echo ( is_numeric($button['link']) ? get_permalink($button['link']) : $button['link'] ); ?>"><?php echo $button['label']; ?></a>
    <?php endif; ?>
  • Thanks @jimkrill. I thought maybe it was just me because I hadn’t heard much from anyone else about this. Your solution works great.

    Because I didn’t want to go back and edit my code after this issue is fixed, I had switched to just using a Post Object field rather than a Page Link, using get_permalink() with the ID, but I think your idea of using is_numeric() is a better solution.

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

You must be logged in to reply to this topic.