Title: the_permalink() returns empty string inside the loop
Last modified: August 19, 2016

---

# the_permalink() returns empty string inside the loop

 *  [vestaviascott](https://wordpress.org/support/users/vestaviascott/)
 * (@vestaviascott)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/the_permalink-returns-empty-string-inside-the-loop/)
 * I’m kinda at a loss on this one. None of my header link URLs are correct because
   my “the_permalink()” statement in the code below is returning an empty string(
   this is inside header.php)…
 * Any ideas what might be the cause?
 *     ```
       <div class="myheader"><div class="myTitle"><a href="/"><?php bloginfo('name'); ?></a></div><div class="myTagline"><?php bloginfo('description'); ?></div><div class="myMenu top"><ul> <?php
       			global $post;
       			$cat=get_cat_ID('my-menu');
       			if($cat > 1)
       				{$myposts = get_posts('numberposts=5&category='.$cat);}
       			else
       				{$myposts = get_posts('numberposts=10');}
       			foreach($myposts as $post) :
       			?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php endforeach; ?></ul></div></div>
       ```
   

Viewing 1 replies (of 1 total)

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/the_permalink-returns-empty-string-inside-the-loop/#post-1293168)
 * You need to run [`setup_postdata($post)`](http://codex.wordpress.org/Template_Tags/get_posts)
   just after the ‘`foreach($myposts as $post) :`‘ or setup your loop [like this one](http://codex.wordpress.org/The_Loop)
   from the Codex:
 *     ```
       <?php $my_query = new WP_Query('category_name=special_cat&posts_per_page=10'); ?>
   
       <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
         <!-- Do special_cat stuff... -->
       <?php endwhile; ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘the_permalink() returns empty string inside the loop’ is closed to new
replies.

## Tags

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

 * 1 reply
 * 2 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/the_permalink-returns-empty-string-inside-the-loop/#post-1293168)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
