• Hi, I want to write a PHP statement that says:


    Check custom field "my_title"
    If "my_title" exists AND "my_title" is not empty {
    echo "my_title";
    } else {
    <?php the_title(); ?>
    }

    I’m a total PHP newbie, please please please help me out. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You’ve practically written it already. I use a global variable that I’ve set elsewhere..

    <?php
    if (isset($GLOBALS[‘dm_forced_title’])) {echo ‘<title>’.$GLOBALS[‘dm_forced_title’].'</title>’;}
    else {
    echo ‘<title>’;
    echo ‘Some Other Title’;
    echo ‘</title>’;
    }
    ?>

    Thread Starter David Wang

    (@blogjunkie)

    Thanks for that mrmist.

    Is there a way for me to just check whether my custom field is empty or not? I would like to use it outside the Loop if possible.

    been looking for similar solution.

    figured it out with the code in this comment.

    so, if you want to check if c2c custom field has any content and echo something based on that this code works for me:

    <?php
    $VARIABLE_ID=c2c_get_custom('CUSTOM_FIELD_NAME');
    if (!empty($VARIABLE_ID)) { echo " BLAHBLAHBLAH "; }
    ?>

    in your code replace:
    VARIABLE_ID with something descriptive (var, var1, var2 etc.)
    CUSTOM_FIELD_NAME with the c2c field name you are checking
    BLAHBLAHBLAH with your content

    if(!empty(...)) means “if the field is NOT empty”

    i’m no PHP guru, all credit to the google for finding that 2005 comment from Nathaniel.

    good luck.
    rak.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Need a PHP lesson’ is closed to new replies.