Display content of most recent custom post type on a page

I’m building a page that will display a list of recent posts of a custom post type at the bottom, with the content of the most recent post displayed as the body of the page.

I’ve got the list of recent posts working, but I can’t seem to figure out the latter half.

Read More

How do I display the body of a custom post type in my template?

Related posts

Leave a Reply

1 comment

  1. One way to accomplish this is to create a new loop that pulls in the most recent custom post type, then displays its title and content.

    <?php
        $new_loop = new WP_Query( array(
        'post_type' => 'YOUR_CUSTOM_POST_TYPE',
            'posts_per_page' => 1 // put number of posts that you'd like to display
        ) );
    ?>
    
    <?php if ( $new_loop->have_posts() ) : ?>
        <?php while ( $new_loop->have_posts() ) : $new_loop->the_post(); ?>
    
              <h2><?php the_title(); ?></h2>
    
              <?php the_content(); ?>
    
        <?php endwhile;?>
    <?php else: ?>
    <?php endif; ?>
    <?php wp_reset_query(); ?>