• Resolved greencode


    I know how to display a custom field if it simply exists:

    $key = 'my-custom-field';
    $themeta = get_post_meta($post->ID, $key, TRUE);
    if($themeta != '') {
    echo 'Display this text if the custom field has been filled in';

    But is there any way to display some different text if that field has been filled in with certain text i.e. If the word Apple is inserted into the custom field I would like Fruit to be displayed on the web page and NOT the word Apple.

    I’m sure there must be a way to question whether a certain word exists in the custom field but I really don’t know how!

    Any help would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • After you’ve got the contents of your custom field, $themeta, you can set-up whatever test case you’d like. For example,

    if ($themeta == 'apple'){
    echo 'fruit';
    } else if ($themeta == 'monkey') {
    echo 'not fruit';
    } else {
    echo 'Not sure if this is fruit...';

    Thread Starter greencode


    Thanks so much for your help with this – very much appreciated.

    Glad it helped.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display text if certain custom field text exists?’ is closed to new replies.