Forums

Custom Field question (3 posts)

  1. lilqhgal
    Member
    Posted 2 years ago #

    I have a custom field that I'm pulling from the database using the following code:

    <?php
    //if custom field is present, formulate and display link from meta value
    $some_var = get_post_meta($post->ID, 'some_var', true);
    if ($some_var){
    echo 'my html and text, and my new custom $some_var';
    }
    ?>

    That works great. Now, I'd like to add in some conditional statement that ONLY shows up if the custom field is filled out. Basically, I want to put a header around the text that $some_var will output. If it's not there, I don't want to have a piece of text floating around that means nothing. For example:

    Who we are:
    $who_we_are_var

    What we do:
    $what_we_do_var

    If the who we are var is empty, I don't want the "who we are" text/html to show up. Any help out there for a non-programmer? Thanks!

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    You question confuses...as you seem to display a solution for the same problem in your code:

    if ($who_we_are_var){
    echo 'there is who we are';
    } else {
    echo 'there is NO who we are';
    }
  3. lilqhgal
    Member
    Posted 2 years ago #

    Ok so I just add an else statement... will give that a try. Sorry for the confusing question. :)

Topic Closed

This topic has been closed to new replies.

About this Topic