Title: Permalink function not working?
Last modified: August 19, 2016

---

# Permalink function not working?

 *  [sumedhinamdar](https://wordpress.org/support/users/sumedhinamdar/)
 * (@sumedhinamdar)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/permalink-function-not-working/)
 * Hi Friends…
 * This is my first post on the forum…so sorry if it’s a wrong category…
 * I have configured my blog smoothly so far…and trying to make some changes to 
   the theme templates…
 * I want to display one category of posts (News) as a separate page, and also display
   separate links section for New and Non-News posts on left sidebar…
 * This is what I’ve written to display links to all but News items (category=7)…
 *     ```
       <div class="box" id="featured">
       <h3>Recent Posts</h3>
       <ul>
       <?php
             $myposts = get_posts('numberposts=5&category=-7'); //GET RECENT POSTS APART FROM NEWS CATEGORY
   
             foreach($myposts as $post) :?>
               <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
             <?php endforeach; ?>
       </ul>
       <div class="cap"></div>
       </div>
       ```
   
 * Now, the_title() gives me correct titles for posts apart from News…but the_permalink()
   gives me blog home page… 🙁
 * I also tried with get_permalink($post->ID), but same result…
 * What is my mistake? 😐

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 6 months ago](https://wordpress.org/support/topic/permalink-function-not-working/#post-856891)
 * Bad way to do it. Make a real Loop using a query instead of trying to use get_posts.
 *     ```
       <?php
       $myquery = new WP_Query('showposts=5&cat=-7');
       while ($myquery->have_posts()) : $myquery->the_post();
       ?>
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
       <?php endwhile; ?>
       ```
   
 *  Thread Starter [sumedhinamdar](https://wordpress.org/support/users/sumedhinamdar/)
 * (@sumedhinamdar)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/permalink-function-not-working/#post-857007)
 * Why is that a bad way? 😐 …I have done it like shown in a code snippet in the
   documentation itself…
 * What is meant by “real loop”?
 * Why does the_title() work and the_permalink() doesn’t?
 * What documentation I’ll need to read to understand when to use which API, and
   when not?
 * I am perplexed! 🙂
 *  Thread Starter [sumedhinamdar](https://wordpress.org/support/users/sumedhinamdar/)
 * (@sumedhinamdar)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/permalink-function-not-working/#post-857011)
 * Strange…
 * The second section that is just below this one, displays the News links…
 * Once I make above changes to the first part (category=-7) as told by you, the
   second part works correctly the previous way, i.e.
 *     ```
       $myposts = get_posts('numberposts=5&category=7'); //GET RECENT POSTS IN NEWS CATEGORY
             foreach($myposts as $post) :?>
               <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
             <?php endforeach; ?>
       ```
   
 * works perfectly fine…
 * So, the first part is making some side effect…does this have something to do 
   with the_post() call…I read documentation for these API’s, but couldn’t figure
   out much…
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 6 months ago](https://wordpress.org/support/topic/permalink-function-not-working/#post-857026)
 * Did you even try the code I posted for you? It does work.
 *  Thread Starter [sumedhinamdar](https://wordpress.org/support/users/sumedhinamdar/)
 * (@sumedhinamdar)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/permalink-function-not-working/#post-857071)
 * Yup…
 * That’s what I am saying…
 * It does work…and the strange part is, my kind of code works in second section(
   category=7) if I use your code for the first section (category=-7)…

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

The topic ‘Permalink function not working?’ is closed to new replies.

## Tags

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

 * 5 replies
 * 2 participants
 * Last reply from: [sumedhinamdar](https://wordpress.org/support/users/sumedhinamdar/)
 * Last activity: [17 years, 6 months ago](https://wordpress.org/support/topic/permalink-function-not-working/#post-857071)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
