0

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.

0

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).

0

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.

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.