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.
Hello friend, Please try this <?php $values = get_post_custom_values("text3"); if($values) { echo $values[0];} else { echo "your content here"; } ?>
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.
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...
Thank you that worked perfectly !! Please check my other thread related to same thing and check if you can solve that problem also ... http://forums.digitalpoint.com/showthread.php?t=2360660