• Resolved raoul_k

    (@raoul_k)


    Hi.

    I’m trying to get a custom post type (called “travel-directory”) into a loop, where the regular blog posts are shown so far.

    I tried a lot of stuff (e.g. this), but couldn’t get it to work. I would be very happy if somebody could help me.

    Here’s the part where I want the custom post type to be included:

    // The Query
    $args['posts_per_page'] = $posts_per_page;
    if (!empty($categories) && $categories[0] !== 'none') {
    	$args['category__and'] = $categories;
    }
    
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
    
    	?>
    	<section class="regular <?php echo esc_attr($blog_class) ?>" <?php echo  $styles; // escaped above ?>>
    		<div class="container">
    
    			<div class="title-row">
    			  <?php if (!empty($section_title)) : ?>
    				<h3 class="title-entry"><?php esc_attr_e($section_title) ?></h3>
    			  <?php endif; ?>
    			  <?php if (!empty($category_link) && !empty($section_more)) : ?>
    				<a href="<?php echo esc_url($category_link); ?>" class="btn btn-primary btn-xs"><?php esc_attr_e($section_more) ?> &nbsp; <i class="fa fa-angle-right"></i></a>
    			  <?php endif; ?>
    			</div>
    
    			<div class="row">
    				<?php
    				while ( $the_query->have_posts() ) : $the_query->the_post();
    
    					get_template_part( 'content-post'.$template_part, get_post_format() );
    
    				endwhile;
    
    				/* Restore original Post Data */
    				wp_reset_postdata();
    
    				?>
    			</div> <!-- /.row -->
    		</div> <!-- /.container -->
    	</section>
    
    	<?php
    
    } // end have_posts()

    Thanks!

The topic ‘Custom post type in Loops’ is closed to new replies.