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 portfolio custom post type with a text field for a site link, I need to echo that link in the template page. What i have so far is this:

            <?php $site= get_post_custom_values('projLink'); 
                if($site[0] != ""){
            ?>
                <span><p><a href="<?php var_dump($site); ?>">Visit the Site</a></p></span>

            <?php }else{ ?>
                <p><em>Live Link Unavailable</em></p>
            <?php } ?>

The problem is that it is not working, I have this on the link:

http://localhost:8888/p3dra/portfolio/array(1)%20%7B%20%20[0]=%3E%20%20string(18)

Thanks.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

I think you can better use get_post_meta(); Your code will look like this:

<?php $site = get_post_meta(get_the_ID(), 'projLink', true); ?>
<?php if(isset($site) && $site != "") : ?>
   <span><p><a href="<?php echo $site; ?>">Visit the Site</a></p></span>
<?php else : ?>
   <p><em>Live Link Unavailable</em></p>
<?php endif; ?>

You use var_dump only for testing purposes (http://php.net/manual/en/function.var-dump.php).

share|improve this answer
    
Works great! Thank you! –  Ricardo Ribeiro Jan 14 '12 at 23:18

Rob's answer should work. If you'd like to still use get_post_custom_values then you need to echo out the answer. Since get_post_custom_values returns an array your code will need to look like this:

    <?php $site= get_post_custom_values('projLink'); 
        if($site[0] != ""){
    ?>
        <span><p><a href="<?php echo $site[0]; ?>">Visit the Site</a></p></span>

    <?php }else{ ?>
        <p><em>Live Link Unavailable</em></p>
    <?php } ?>

Keep in mind though that it will only post the first custom value. So make sure that in the post the link you want to echo is the first projLink custom value.

share|improve this answer

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.