Forums

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

  1. thejonson
    Member
    Posted 3 months 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 3 months ago #

    <?php
    $key = 'field_name';
    $themeta = get_post_meta($post->ID, $key, TRUE);
    if($themeta != '') {
    echo 'your text';
    }
    ?>

Reply

You must log in to post.

About this Topic