Forums

Need a PHP lesson (4 posts)

  1. blogjunkie
    Member
    Posted 4 years ago #

    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!

  2. mrmist
    Forum Janitor
    Posted 4 years ago #

    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>';
    }
    ?>

  3. blogjunkie
    Member
    Posted 4 years ago #

    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.

  4. rakpress
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic