I used WP_Query to get related post in the same category but when showing to html, the category names appear on top of the posts. How can I remove them by setting parameters to WP_Query and not using CSS?
<ul class="post-categories">
<li>...</li>
<li>...</li>
</ul>
PHP:
<?php
$relateds = new WP_Query(array('post_type' => 'post',
'posts_per_page' => 10, 'cat' => the_category(), 'post__not_in'
=> array(get_the_ID())));
if ( $relateds->have_posts() ):
while ( $relateds->have_posts() ): $relateds->the_post(); ?>
<a href="<?php the_permalink() ?>" class="media">
<div class="d-flex align-self-start">
<?php the_post_thumbnail(); ?>
</div>
<div class="media-body pl-3">
<div class="media-title">
<?php echo wp_trim_words(get_the_title(), 15); ?>
</div>
</div>
</a>
<?php endwhile; else: endif;
wp_reset_postdata(); ?>
</aside><!-- /.blog-sidebar -->
<?php endwhile; ?>
Current result is st like this:
Category 1
Category 2
Post 1
Post 2
Post 3
...
But I want only:
Post 1
Post 2
Post 3
To remove categories, just remove function the_category() of the variable $relateds, so to do this, change:
to:
Hope this help you!