Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a field on my portfolio admin page which shows the url when the user write a url(obviosly).

I want to when the user write in the field, elements appear along with it. And if the field is empty dont shows anything.

The code that shows what the user is writing in this field is:

<?php echo get_post_meta($post->ID, '_url', TRUE);?>

I tried:

<?php if (strpos($post->ID,'_url') !== true) {   ?>

        [CONTENT] <?php echo get_post_meta($post->ID, '_url', TRUE); ?> [/CONTENT]

<?php } ?>
share|improve this question
    
What exactly are you trying to do? Why do you have [CONTENT] in your code? –  Jacob Rambo Mar 9 '13 at 1:09
    
is the rest of content like <p> <a href> and other codes –  Chead Mar 9 '13 at 1:10
    
i want if the custom metabox in my admin is empty, nothing below "if" will show –  Chead Mar 9 '13 at 1:11
add comment

1 Answer

up vote 0 down vote accepted

Just write a if statement using the get_post_meta like this

<?php if(get_post_meta($post->ID, '_url', true)){?>

 <p> Display some stuff.</p>

<?php } ?>

There is an example here http://codex.wordpress.org/Function_Reference/get_post_meta

share|improve this answer
    
Parse error: syntax error, unexpected '{' –  Chead Mar 9 '13 at 1:21
    
Sorry, Had a typo see my edit. –  Jacob Rambo Mar 9 '13 at 1:22
    
Thanks Jacob! Is working fine now :} –  Chead Mar 9 '13 at 1:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.