Title: Custom field in hyperlink, inside recent posts
Last modified: August 20, 2016

---

# Custom field in hyperlink, inside recent posts

 *  Resolved [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/custom-field-in-hyperlink-inside-recent-posts/)
 * I’m trying to “pull” a custom field into a hyperlink address. Problem is, I think
   I’m getting too deep in the coding. I pulled this code from WordPress Codex to
   display my recent posts by tag.
 *     ```
       <?php
           $key = 'member-name';
           $tag = get_post_meta($post->ID, $key, true);
           $args=array(
       	'numberposts' =>5,
       	'tag' => $tag,
       	'orderby' =>'post_date',
       	'order' => 'DESC',
           );
       $my_query = new WP_Query($args);
           if( $my_query->have_posts() ) {
       	      echo 'Recent News:';
             while ($my_query->have_posts()) : $my_query->the_post(); ?>
               <li>
       <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php
       the_title_attribute(); ?>"><?php the_title(); ?
       ></a>
       </li>
              <?php
             endwhile;
           } //if ($my_query)
         wp_reset_query();  // Restore global post data stomped by the_post().
       ?>
       ```
   
 * But now I want to add an RSS feed image next to Recent News, which isn’t a problem.
   It’s when I want to link that image to the page’s custom field that gets to be
   a problem. I have tried a number of combinations but this seemed to make the 
   most sense to what I’m trying to do…but it doesn’t work.
 *     ```
       <?php
           $key = 'member-name';
           $tag = get_post_meta($post->ID, $key, true);
           $args=array(
       	'numberposts' =>5,
       	'tag' => $tag,
       	'orderby' =>'post_date',
       	'order' => 'DESC',
           );
       $my_query = new WP_Query($args);
           if( $my_query->have_posts() ) {
       	      echo '<a href="../tag/<?php $key= "member-name"; echo get_post_meta($post_ID,$key,true); ?>/feed">
       <img src="../wp-content/uploads/RSSfeed24transparent.png" /></a> Recent News:';
             while ($my_query->have_posts()) : $my_query->the_post(); ?>
               <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php 
   
       the_title_attribute(); ?>"><?php the_title(); ?></a></li>
   
              <?php
             endwhile;
           } //if ($my_query)
         wp_reset_query();  // Restore global post data stomped by the_post().
       ?>
       ```
   
 * The problem arises with this part of the code:
    `<a href="../tag/<?php $key= "
   member-name"; echo get_post_meta($post_ID,$key,true); ?>/feed">` I have plugged
   in one of the values in the place of the php script, and I got what I was looking
   for. So I’m just wondering if I’m getting too deep in the code and need extra()
   or {} or something like that to help separate it?

Viewing 1 replies (of 1 total)

 *  Thread Starter [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/custom-field-in-hyperlink-inside-recent-posts/#post-3028395)
 * I figured this out on my own – I put the RSS image before all of the PHP code
   and it displayed perfectly.

Viewing 1 replies (of 1 total)

The topic ‘Custom field in hyperlink, inside recent posts’ is closed to new replies.

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [hyperlink](https://wordpress.org/support/topic-tag/hyperlink/)
 * [my_query](https://wordpress.org/support/topic-tag/my_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/custom-field-in-hyperlink-inside-recent-posts/#post-3028395)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
