0

I have a custom post type called airports which uses a template called single-airports.php.

I have created a new airport called Gatwick and created a child of this called called Gatwick North Terminal.

How do I get the permalink of Gatwick's children to display on the Gatwick page (single-airports.php).

I would greatly appreciate any help provided!

0

1 Answer 1

1

After some digging I found the answer!

Hopefully this helps some other people!

EDIT

Improved Answer!

<?php
$args = array( 'post_parent' => get_the_ID(), 'post_type' => 'airports', 'posts_per_page' => -1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>

<h2><?php the_title(); ?></h2>
<a href="<?php the_permalink(); ?>">
    <button><?php _e('View', 'text_domain'); ?></button>
</a>

<?php endwhile;  wp_reset_postdata(); ?>
4
  • Unfortunately this is totally wrong. One should never ever use query_posts() Commented Apr 5, 2016 at 15:04
  • Darn. Can you please elaborate? Commented Apr 5, 2016 at 15:09
  • @PieterGoosen I've amended my answer! Is that any better? Commented Apr 5, 2016 at 15:17
  • 1
    Much better. I have removed the other wrong section of code. Just a note, you should use wp_reset_postdata() (I have fixed that). wp_reset_query() is used with query_posts() ;-) You should read this post Commented Apr 5, 2016 at 15:21

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.