Hi I’ve made a custom post type ‘work_fields’ that calls in information from yet another custom post type ‘members’ into the post, and now I’m trying to make a PAGE TEMPLATE that shows a list of the titles of custom post type ‘work_fields’, and when you click a title, the whole post(‘work_fields’) will show up on a div called ‘single-post-container’ below the titles. right now I’ve got everything working fine, but I want to display a post in the div ‘single-post-container’ when the page loads. (as of now, just the titles of the posts are displayed and there is nothing in the div). How do I get the div to display the most recent post of custom post type ‘work_fields’? This is the code for the custom page template.

<div class="row">
  <div class="small-12 medium-10 large-offset-1 columns">
    <h2><?php the_title(); ?></h2>
  </div>
</div>  
<div class="row halfsection">
  <div class="small-12 medium-10 large-offset-1 columns">
    <div class="category_container">
    <?php
        $args = array('post_type' => 'work_fields',);
        $query = new WP_Query( $args );
    ?>

    <?php if ( $query->have_posts() ) : ?>
      <?php while ( $query->have_posts() ) : $query->the_post(); ?>  
        <p class="category_item"><a class="post-link" rel="<?php the_ID(); ?>" href="<?php the_permalink(); ?>"><?php  echo get_the_title(); ?></a></p> 
    <?php endwhile; endif; ?>
    </div>
  </div>
</div>
<div class="row">
  <div class="small-12 medium-10 large-offset-1 columns">
    <hr>
  </div>
</div>                      
<div id="single-post-container">
    //THIS IS WHERE THE POST CONTENTS SHOWS BUT I WANT THE MOST RECENT POST TO BE HERE ON PAGE LOAD, BEFORE I CLICK ANY OTHER POST//    
</div>

Thank you! Your help is much appreciated!

Read more here: How do you print an entire post into a page (wordpress)


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: