Forums

[resolved] Don't display custom field if containing specific value (3 posts)

  1. Ella
    Member
    Posted 2 years ago #

    I have a custom field called "warning", which I use for common content advisory notices. The default value for this custom field is "None" as I wanted to give people the option of filtering posts to include only those that have no content advisory notices. I would like to display the "warning" filed in my posts only when the value is NOT "None". Is this possible? Can someone explain how or point me to some examples?

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    <?php if(get_post_meta($post->ID, 'warning', true) != 'None') { ?>
    <!--possible html tags here-->
    <?php echo get_post_meta($post->ID, 'warning' ,true); ?>
    <!--possible closing html elements here-->
    <?php } ?>
  3. Canha
    Member
    Posted 2 years ago #

    Explaining alcymyth's code:
    <?php if(get_post_meta($post->ID, 'warning', true) != 'None') { ?>
    If the "warning" is NOT none, do stuff.

    <?php echo get_post_meta($post->ID, 'warning' ,true); ?>
    Show contents of the "warning".

    If this topic is solved, please mark it as "Resolved" on your right sidebar.

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Topic