Support

Account

Home Forums General Issues Page link fields

Solving

Page link fields

    • deejr

    • July 22, 2014 at 1:46 am

    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>';
    }
    • deejr

    • July 22, 2014 at 4:28 pm

    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

    • deejr

    • July 23, 2014 at 7:58 am

    Anyone else got any ideas?

    • deejr

    • July 23, 2014 at 8:18 am

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.