March 8, 2012

Simple php if !empty-function

Question by Jörg Mayer

I want to simply echo a link (set in a custom field in WordPress), when the corresponding field is not empty.

I tried the following, but the output is missing the link. Only the field as plain text gets printed

<?php $projekt_link = the_field('link');                                    
    echo '<a href="'.$projekt_link->name.'" class="button">Zum Projekt</a>';

Answer by Starx

If you are using the Advance Custom Fields plugin, then the correct syntax is

$projekt_link = get_field('link');

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!