1

i have custom post type events. i want to display content from single post and using single-events.php . The code in single-events.php is

<?php get_header(); ?>

<?php $args = array( 'post_type' => 'events',
                   );

              $loop = new WP_Query( $args );
  if($loop->have_posts()):while ( $loop->have_posts() ) : $loop->the_post();  ?>

<?php the_content( ); ?>

<?php endwhile;endif; ?>    

<?php get_footer(); ?>

But its displaying the content from all of the posts of custom type- 'events': how do i display the post from just single post

terminator
  • 159
  • 3
  • 19

2 Answers2

1

The events post object should already be in $wp_query - you don't need to reinitialise it. Just process it with the standard WordPress loop. Something like (untested):

<?php get_header();

if(have_posts()):while ( have_posts() ) : the_post();
    the_content( );
endwhile;endif;

get_footer(); ?>
Hobo
  • 7,536
  • 5
  • 40
  • 50
0

List and single event for same file call. see the step:

you can change structure for single event so go hear

<?php
/**
 * Template Name: Event page
 */
get_header(); ?>

<div id="main-content" class="main-content">
    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">
                    <div class="page_content">
                            <div class="content_wrapper">
                                    <?php
                                        while ( have_posts() ) : the_post();
                                                get_template_part( 'content', 'page' );
                                        endwhile;
                                    ?>

                            </div>
                    </div>
                </div><!-- #content -->
    </div><!-- #primary -->
</div><!-- #main-content -->
<?php
get_footer();

enter image description here

if(get_post_type()=='tribe_events' && is_single() ) { 
    while ( have_posts() ) : the_post();
        get_template_part( 'content', get_post_format() );
    endwhile;

} else { 

    //for list code
}
Ravi Patel
  • 5,121
  • 2
  • 25
  • 44