Get Posts Under Categories Wordpress | Custom Post Type
Copy Below Code
View As A Text File
Show Text Only
Show API
Edit Code
<?php
$args = array(
'type' => 'nchr_report',
'orderby' => 'id',
'order' => 'ASC',
'hierarchical' => 1,
'pad_counts' => false
);
$categories = get_categories($args);
foreach( $categories as $category ) { ?>
<section class="report-block">
<h2><?php echo $category->name; ?></h2>
<div class="container">
<div class="report-list">
<?php
$postArgs = array(
'post_type' => 'nchr_report',
'category_name' => $category->slug,
'orderby' => 'date',
'order' => 'DESC',
);
$loop = new WP_Query($postArgs);
// echo "<pre>"; print_r($loop); exit;
if( $loop->have_posts() ) : ?>
<?php while( $loop->have_posts() ) : $loop->the_post();
$post_id = get_the_ID();
$file=get_field('file',$post_id);
?>
<div class="col-lg-3 report-box">
<a href="<?php echo $file; ?>" target="_blank">
<img src="<?php echo the_post_thumbnail_url(); ?>" />
<label><span> <?php echo the_title(); ?></span></label>
</a>
</div>
<?php endwhile ?>
<?php endif ?>
</div>
</div>
</section>
<?php }
?>