0

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 } ?>
  • 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
0

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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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