Title: Loop Issue
Last modified: June 8, 2020

---

# Loop Issue

 *  Resolved [nnproducts](https://wordpress.org/support/users/nnproducts/)
 * (@nnproducts)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/loop-issue-2/)
 * Trying to insert the URL for any given organization into a list of search results.
   The following inserts the post metadata for the custom field ‘link’ but inserts
   the first item’s URL for all subsequent items in the results. Obviously, I need
   the URL for each individual organization. Not sure what I am missing.
 *     ```
       <!-- Loop -->
        <?php 
       	$link = get_post_meta(get_the_ID(), 'link', TRUE);
               if ( have_posts() ) { 
                   while ( have_posts() ) : the_post(); ?>
       		<p><a href="<?php echo $link; ?>"><?php the_title(); ?></a></p>
       		<?php
                       get_template_part( 'parts/content', get_post_format() );
                   endwhile;
       	} 
               else { ?>
               <div class="no-results"><p><?php _e('No posts found.', 'vega'); ?></p></div>
               <?php } ?>
       <!-- /Loop -->
       ```
   
 * Any assistance appreciated.
 * Thanks!
    -  This topic was modified 5 years, 10 months ago by [nnproducts](https://wordpress.org/support/users/nnproducts/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [VIPStephan](https://wordpress.org/support/users/10010110/)
 * (@10010110)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/loop-issue-2/#post-12957190)
 * You should probably do this _inside_ the loop, i. e.:
 *     ```
       <?php 
       	if ( have_posts() ) { 
       		while ( have_posts() ) : the_post();
       			$link = get_post_meta(get_the_ID(), 'link', TRUE);
       ?>
       			<p><a href="<?php echo $link; ?>"><?php the_title(); ?></a></p>
       …
       …
       ```
   
 *  Thread Starter [nnproducts](https://wordpress.org/support/users/nnproducts/)
 * (@nnproducts)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/loop-issue-2/#post-12957233)
 * [@10010110](https://wordpress.org/support/users/10010110/),
 * I tried that, but, I think that I must have had the syntax wrong. Working now!
 * Thank you for the quick reply!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Loop Issue’ is closed to new replies.

## Tags

 * [get_post_meta](https://wordpress.org/support/topic-tag/get_post_meta/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [nnproducts](https://wordpress.org/support/users/nnproducts/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/loop-issue-2/#post-12957233)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
