Might be a conditional tag help required ..

Discussion in 'WordPress' started by Rajnish357, Dec 11, 2011.

  1. #1
    I have custom field on create new post page
    <textarea style="width: 95%;" name="text3">Text In the Field</textarea>
    Which outputs on the single.php
    with this code:
    <?php $values = get_post_custom_values("text3"); echo $values[0]; ?>
    PHP:
    I want that if the field has content then it display the content other wise display the predefined content.
     
    Rajnish357, Dec 11, 2011 IP
  2. ShinoRex

    ShinoRex Well-Known Member

    Messages:
    227
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    148
    #2
    Hello friend, Please try this

    <?php $values = get_post_custom_values("text3");

    if($values)
    {
    echo $values[0];}
    else
    {
    echo "your content here";
    }
    ?>
     
    ShinoRex, Dec 14, 2011 IP
  3. Rajnish357

    Rajnish357 Well-Known Member

    Messages:
    157
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Thanks You ShinoRex,
    That code worked perfectly but after I kept that I realized that if that filed it empty I can keep another field instead of that, So can you please help me with this ?

    I want that if the "text3" field does not have text then it should show text of "text2" field and if that is also empty the it should show text of "text1" field and if that is also empty then it show a custom text.

    Please Help! I will be really very thankful to you for that.

     
    Rajnish357, Dec 21, 2011 IP
  4. ShinoRex

    ShinoRex Well-Known Member

    Messages:
    227
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    148
    #4
    You can do this by the following code,

    <?php

    $text1Val = get_post_custom_values("text1");
    $text2Val = get_post_custom_values("text2");
    $text3Val = get_post_custom_values("text3");

    if($text1Val)
    {
    echo $text1Val[0];
    }
    else if($text2Val)
    {
    echo $text2Val[0];
    }
    else if($text3Val)
    {
    echo $text3Val[0];
    }
    else
    {
    echo "your content here";
    }
    ?>


    Hope this will help you...:)
     
    ShinoRex, Dec 21, 2011 IP
  5. Rajnish357

    Rajnish357 Well-Known Member

    Messages:
    157
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Rajnish357, Dec 25, 2011 IP
  6. ShinoRex

    ShinoRex Well-Known Member

    Messages:
    227
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    148
    #6
    Thank you.. happy..:)
     
    ShinoRex, Dec 27, 2011 IP