WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
[resolved] If condition (4 posts)

  1. rider111
    Member
    Posted 1 year ago #

    Hi,
    how I can call the field in a if function?
    I need something like if my custom field is empty show Text1 else show Text2.
    Thank you in advance for your precious support.
    Greetings

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. Harrison O.
    Member
    Posted 1 year ago #

    <?php if( get_post_meta($post->ID, "mycustomfieldname", true) ): ?>
    <?php echo get_post_meta($post->ID, "mycustomfieldname", $single = true);?>
    <?php else: ?>
    text 2 (add your default message here).
    <?php endif; ?>

    If you have added something to the custom field (mycustomfieldname), then it will be displayed by the second line code.
    If you have it blank, then it'll show any default text you add it as default.

  3. rider111
    Member
    Posted 1 year ago #

    Thank you so much, it works perfect :D
    Thanks again

  4. elliotcondon
    Member
    Plugin Author

    Posted 1 year ago #

    Have a look at the get_field function. It's a lot cleaner than what you are using.

    http://www.advancedcustomfields.com/docs/functions/get_field/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags