0

I'm building a traveling-page and i need to add the description of a train or a ship into the description of a trip. My code looks like this:

<?php if (!empty(rwmb_meta("train_ship"))) { ?>
   <div class="maxtext_detail">
      <?php $get_train = get_post( get_post_meta( $post->ID, "train_ship", true) );
      setup_postdata( $get_train ); ?>
      <h3><?php the_title(); ?></h3>
      <p><?php the_content(); ?><a href="#" data-toggle="modal" data-target="#myModal">Read More</a></p>
   </div>

   <!-- Modal -->
   <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
     <div class="modal-dialog" role="document">
        <div class="modal-content">
           <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="myModalLabel"><?php the_title(); ?></h4>
           </div>
         <div class="modal-body">
       <?php the_content(); ?>
     </div>
   </div>
 </div>

This is inside the Loop of a single.php. My problem is that the content only displays the text before the "read more" tag that I added to the post of the train. This is actually what i want to do with the first the_content, but the second should display the full content. Does anyone know why only the parts before the read more are displayed?

Thanks for your help

0

Check out the examples on the setup_postdata Codex page. You must pass a reference to the global $post, it won't work with any other variable.

global $post;            // make sure we're working with the global.
$post = $get_train;      // or assign get_post result directly to $post.
setup_postdata( $post ); // this must be the global $post.

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.