Skip to content

Instantly share code, notes, and snippets.

@alana-mullen
Last active March 25, 2018 02:19
Show Gist options
  • Save alana-mullen/5745760 to your computer and use it in GitHub Desktop.
Save alana-mullen/5745760 to your computer and use it in GitHub Desktop.
Display the title and thumbnail of child custom post types on the parent custom post type
<?php
$pageChildren = get_pages('child_of='.$post->ID."&echo=0&post_type=custompostypename");
if ( $pageChildren ) {
foreach ( $pageChildren as $pageChild ) {
echo '<a href="' . get_permalink($pageChild->ID) . '">';
$childimage = wp_get_attachment_image_src(get_post_thumbnail_id($pageChild->ID), 'thumbnail_size');
$childimagealttext = get_post_meta(get_post_thumbnail_id($pageChild->ID), '_wp_attachment_image_alt', true);
echo '<img src="'. $childimage['0'] . '" alt="' . $childimagealttext . '"/></a>';
echo '<p><a href="' . get_permalink($pageChild->ID) . '">'. $pageChild->post_title.'</a></p>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment