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!


After some digging I found the answer!

Hopefully this helps some other people!


Improved Answer!

$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>

<?php endwhile;  wp_reset_postdata(); ?>
  • Unfortunately this is totally wrong. One should never ever use query_posts() Apr 5 '16 at 15:04
  • Darn. Can you please elaborate? Apr 5 '16 at 15:09
  • @PieterGoosen I've amended my answer! Is that any better? Apr 5 '16 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 Apr 5 '16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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