Pulling custom meta into widget (3 posts)

  1. kfawcett
    Posted 5 years ago #

    Hello all,

    I'm hoping someone can help me. I have a custom meta field in my back end post editor that allows for someone to enter a URL. I am pulling this into the loop to display on the bottom of my posts on the main page using get_post_meta.

    I now want to display that link on the single page posts also. Preferably with a widget. There are a few different widgets that allow php, but I'm not sure if they are able to do what I want. Does anyone know of a way to accomplish this?

    Here is a snippet of the code that I am using in the loop page:

    <?php while (have_posts()) : the_post();
    //Post Link
    $post_link = get_post_meta($post->ID, 'soy_post_link', true);
    <a href="<?php echo $post_link; ?>">Visit Source</a>

    Thanks in advance,

  2. wpua
    Posted 5 years ago #

    Hi Keith,

    Using "PHP Code Widget" you can do this with such code:

      global $post;
      $post_link = get_post_meta($post->ID, 'soy_post_link', true);
      echo "<a href=\"$post_link\">Visit Source</a>";

    Let me know if you need something more.

  3. kfawcett
    Posted 5 years ago #

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic