Forums

[resolved] Check if a custom field exists (3 posts)

  1. thejonson
    Member
    Posted 2 years ago #

    is it possible to check if a custom field exists and then if it does display some arbitrary text.

    My plan is to get wordpress to check if a post contains a custom field "photoBoxID" and if it does display the text "For Sale", I have already got it using the value of "photoBoxID" to link to the shop page, I just need some way of advertising the fact that an image is on sale.

  2. doodlebee
    Member
    Posted 2 years ago #

    <?php
    $key = 'field_name';
    $themeta = get_post_meta($post->ID, $key, TRUE);
    if($themeta != '') {
    echo 'your text';
    }
    ?>
  3. WPExplorer
    Member
    Posted 1 year ago #

    OMG thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic