Support

Account

Home Forums General Issues Page link fields

Solving

Page link fields

  • Hi I am really new to php so sorry for the ignorance.

    I have set up a page link field which I can get to echo out the page link in html text by using the following.

    if(get_field('linkedto')){
    $field_name = "linkedto";
    $field = get_field_object($field_name);
    echo '<strong>', $field['label'],'</strong>' . ': ' . $field['value'],'</br>';}

    What I am struggling with is making the thing output a link with the post title as the link name and the whole thing it a link to the post in question.

    Hope someone can help a newbie out on this please. I am using genesis and for some reason I have to echo everything out – don’t ask why but so far I have a nice list of fields in HTML but just struggling to work out the page link thing.

  • Hey, try this:

    $id = get_field('linkedto');
    if ($id) {
        echo '<a href="' . get_permalink($id) . '">';
            echo get_the_title($id);
        echo '</a>';
    }
  • Hi Philipp thank you for that, it certainly doesn’t break anything but all it returns when I look in firedbug is

    No link inside…hmm

    Thank you though

  • Anyone else got any ideas?

  • If it helps anyone the code kindly offered above out puts

  • The Page Link field only returns a URL, so the title isn’t returned. Change your field type to Post Object and it’ll work.

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

The topic ‘Page link fields’ is closed to new replies.