How to display content from post_parent

As stated by the other answer, you can not pass an ID to get_the_content() function. You could fetch the post using get_post(), but there’s also another handy function that you can use to fetch the content:

The get_post_field( $field, $post_id, $context ) function is what you’re looking for:

$content = apply_filters( 'the_content', get_post_field( 'post_content', $post->ID ) );

The the_content filter also makes sure that some features like shortcodes or auto-paragraphs will work as intended.

Simply replace your second <a>...</a> with this:

<?php echo apply_filters( 'the_content', get_post_field( 'post_content', $post->post_parent ) ); ?>

Leave a Comment

tech