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) {
wp_reset_query();
$args = array('post_type' => 'services',
'tax_query' => array(
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>
</div>
</div>
<?php
endwhile;
} } } }
echo get_post_permalink()
, or justthe_permalink()
. You're currently outputting nothing.