• Hi, im interested in having a custom field “url” and in the value, add a url, that part is easy

    however I want to create a function $site, which can be echo´d inside of single.php in order to reproduce the value, I have no idea how to do this, Ive searched the codex, and it provides examples for slightly more complex things, such as showing the values of all custom fields in an array or ordered list and it gets a bit confusing for me

    I’ve tried using

    <?php $site = get_post_meta($post->ID, 'site', true); ?>
    <?php echo $site; ?>

    thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Is the name of your Custom Field ‘site’? If so, the code you showed should work. If the name of the CF is ‘url’, then you need this:

    <?php $site = get_post_meta($post->ID, 'url', true); ?>
    <?php echo $site; ?>
    Thread Starter dlusionz

    (@dlusionz)

    hi, thanks for the answer, the name of the CF is indeed “site”, but its not exactly working, It apparently is not retrieving de post ID correctly, if I refer to it manually it works, but if I don’t it does´t echo anything

    do you have any ideas?

    Thread Starter dlusionz

    (@dlusionz)

    hey! I read up on some similar but significantly different posts on here and I fixed it now, it seems I needed to have
    <?php global $post; ?> before anything

    thanks again though!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to retrieve custom field value as a function’ is closed to new replies.