• Resolved The-Dude

    (@the-dude-1)


    Hi Corey,

    first, thanks für coding this very usefull ACF-Option! I realy need it!
    Unfortunatly it doesn’t work.

    Instead of displaying the linked Link-Text, i see only the word “Array”.

    Could you please help me? ??

    Big Thx!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Corey Worrell

    (@coreyw)

    @the-dude-1, thank you for downloading.

    The link field actually returns an array value, not a single string value.

    array(
        [url]    => https://site.com/page/
        [title]  => Page!
        [target] => 0
    )

    So you can get the value you need by using something like this:

    $link = get_field('my_link');
    echo sprintf('<a href="%s">%s</a>', $link['url'], $link['title']);
    Thread Starter The-Dude

    (@the-dude-1)

    Hi Corey,

    thanks for the hint, but where should i integrate the code? Should i change your plugin-code?

    And why does it not work out of the box, like i assumed? I thought, i enter Link and Link text in the ACF-backend, and see the linked text at the front end.

    Cheers ??

    • This reply was modified 7 years, 8 months ago by The-Dude.
    Plugin Author Corey Worrell

    (@coreyw)

    @the-dude-1,

    It does work out of the box, just not the way you are expecting. The code above can be placed in your theme template file, or anywhere you are trying to display the value.

    ACF uses the function get_field to display a value: https://www.advancedcustomfields.com/resources/code-examples/

    The Link field behaves just the same as an Image or File field would, they all return an array from the get_field function. https://www.advancedcustomfields.com/resources/file/

    Thread Starter The-Dude

    (@the-dude-1)

    Ah, ok. That’s not what i want. Perhaps it implement it into the theme, all the work and information is gone with next theme update.

    I thought it behaves and i can use it like the other ACF fields: Define it in a field group, fill in the information in the backend and see the result in the front end. No coding.

    • This reply was modified 7 years, 8 months ago by The-Dude.
    Plugin Author Corey Worrell

    (@coreyw)

    @the-dude-1,

    That is how it works, but your theme must support it. And to make changes to a theme without updates overwriting them, you must create/use a child theme.

    If you are using a commercial theme, I would contact them regarding the issue to see if they can add support for this ACF field type.

    Thread Starter The-Dude

    (@the-dude-1)

    Thanks for this important hint. Yes, i’m using a commercial theme (and a child them of course ;)) that comes with ACF. Ok, then i talk to the theme developers. ??

    Plugin Author Corey Worrell

    (@coreyw)

    You’re welcome! Hope they can help you get it figured out.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Does not work, returns the word “Array”’ is closed to new replies.