I don't think this is the most elegant way of achieving my objective but it's 95% there.

I have created a page template and added a post loop to list custom posts based on the a custom field set on the page.

I am trying to show a list of associated posts. I have a custom taxonomy 'servicestax' containing values such as 'design' and 'support' I want to show the posts for my custom post type 'Services' with a link to the post.

The issue i face is the permalink is output as the current page url and not a post url from the list of custom posts. I don't really understand why this should be as the thumbnail, title and excerpt all appear as expected.

The code I have cobbled together is as follows (I have added too much error checking yet!)

 $key_value = get_field('post_types' );
$custom_terms = get_terms('servicestax');
   foreach($custom_terms as $custom_term) {
$args = array('post_type' => 'services',
    'tax_query' => array(
            'taxonomy' => 'servicestax',
            'field' => 'slug',
            'terms' => $custom_term->slug,
if (! empty($key_value)){
if ($custom_term->slug == $key_value->slug){
 $loop = new WP_Query($args);
 if($loop->have_posts()) {
    while($loop->have_posts()) : $loop->the_post(); ?>
    <div class="listing col-md-8">
    <h3><a href="<?php get_post_permalink()?>"><?php the_title()?> </a></h3>
         <div class="col-md-3 col-sm-3 hidden-xs"><img class=" hidden-xs" src=" <?php the_post_thumbnail_url( 'thumbnail' )?>"/></div>
         <div class="col-md-9 col-sm-9">
        <?php the_excerpt() ?>
        <a href="<?php get_post_permalink()?>">more information</a>
 }   }   }   }
  • 2
    You need echo get_post_permalink(), or just the_permalink(). You're currently outputting nothing.
    – Milo
    Commented Nov 17, 2016 at 16:03
  • Slightly embarrassing, thank you for spotting such a basic error!
    – clueleast
    Commented Nov 18, 2016 at 8:17

2 Answers 2


You just need to echo get_post_permalink()

  <?php echo get_post_permalink();?>

get_post_permalink() just get the permalink, you need to tell PHP to insert the same there so the use <?php echo get_post_permalink();?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.