Answer the question
In order to leave comments, you need to log in
How to display custom post types in WP?
He brought out the necessary headings, but all the posts inside are displayed, and not the necessary headings.
<?php
$arg_cat_one = array(
'orderby' => 'include',
'order' => 'ASC',
'hide_empty' => 0,
'exclude' => '',
'include' => '2,3,4',
'taxonomy' => 'typeofservice'
);
$categories_one = get_categories( $arg_cat_one );
?>
<!-- 1 -->
<div class="services-row--one">
<?php
if( $categories_one ){
foreach( $categories_one as $cat ){
?>
<?php
$arg_posts = array(
'orderby' => 'name',
'order' => 'ASC',
'post_per_page'=> -1,
'post_type' => 'service',
'post_status'=> 'publish',
'cat' => $categories_one -> cat_ID,
);
?>
<?php $query = new WP_Query($arg_posts); ?>
<div class="services-item">
<a href="">
<div class="services-item__img"><img src="<?php echo get_template_directory_uri();?>/img/@2x/services01.png" alt="alt"></div>
<div class="services-item__title"><a href=""><?php echo $cat -> name; ?></a></div>
<ul class="services-item__list">
<?php if ($query -> have_posts() ) while ($query -> have_posts() ) : $query -> the_post(); ?>
<li><a href=""><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_postdata()?>
</ul>
</a>
</div>
<?php
}
}
?>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question