Forums

[resolved] Pulling in custom field within loop on category page (3 posts)

  1. danbranigan
    Member
    Posted 2 years ago #

    Hi there,

    I'm trying to pull a custom field from my posts from within the loop on my category.php template. I'm using $post->ID to retrieve the post ID within my get_post_meta() function - but it's not working.

    I've tested it by actually setting a value for the post ID, e.g. 1 and it works fine then. Strange I haven't had this problem pulling in meta data on posts or pages?

    I've also tried setting a variable, e.g.

    $link_ID = $post->ID, and then using this new variable in the get_post_meta() function. But gain , no joy. Weird ;cos when I echo the value of the $link_ID variable it does seem to be picking up the correct value!!

    Any help appreciated.

    regards

    Dan

  2. danbranigan
    Member
    Posted 2 years ago #

    Sorry, here's my code:

    <?php $external_link = get_post_meta($post->ID, 'external-link', true); ?>
    <a class="external-link" href="<?php echo $external_link; ?>" target="_blank">Buy now from Nauticalia &raquo;</a>
  3. danbranigan
    Member
    Posted 2 years ago #

    Sorry I fixed it I was being a complete muppet!!!

Topic Closed

This topic has been closed to new replies.

About this Topic