wordpress if / else for custom fields

Hello, I have a set of custom fields which are not always populated. I need to display them if populated and either display nothing or display a message if they are not.

This is the code to display the fields on the page.

 <h6><span>By: </span><?php yyy_authors(); ?>. <span>Updated on:</span> <?php yyy_date_updated(); ?>. <span>Document type:</span> <?php the_field('document_type'); ?></h6>

Open in new window

So for the sake of figuring this out I'd like it to display the word 'unkown' if any of the fields are empty.

I know I need to be using an if / else but not sure how so can anyone please point me in the direction?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You're using ACF? :)
I'm assuming so because of the call to the function the_field(), the_field() returns false if no value is set.

$document_type = get_field('document_type');
if  ($document_type) {
  echo $document_type;
} else {
  echo 'unknown';

Open in new window

igloobobAuthor Commented:
Hi it's actually using ACF for one of the fields but a different plugin for the other two (it's a private plugin pulling documents from external sources that I was supplied with as part of the job).

<?php yyy_authors(); ?>
<?php yyy_date_updated(); ?>

are the ones from the other plugin.

I tried your code above but it just returns 'unknown'
Unfortunately, I don't know what that other plugin is by looking at those two functions, I have never encountered them before.

ACF is completely documented here: http://www.advancedcustomfields.com/resources/

For example, i swapped the function you were using "the_field()" that outputs the value stored in the field with the function "get_field()" that returns the value so that you can use/test it before display.

It appears that these other two functions from the other plugin are also display functions. You need to find out if they have equivalent "get" type functions, use those functions and then test your values before displaying them. Your best hope at finding out what to replace those functions with is the plugin documentation, if there is any.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
igloobobAuthor Commented:
hi sorry for the delay, I've been on other jobs.

I spoke to the developer and he set it up to include get functions for the fields, it's a custom plugin that's still in development.

Thanks for the advice on that.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.