1
Fala galera,
I am developing a wordpress theme, and on a page I use a function to pick up related posts, it picks up all posts to the current. But he wouldn’t need to take the current one, what would be the way to delete the current post and actually show only related ones?
NOTE: I am using a custom_post_type=courses
Thanks!!!
function postagem_relacionada() {
$post_id = get_the_ID();
$cat_ids = array();
$categories = get_the_category( $post_id );
if(!empty($categories) && is_wp_error($categories)):
foreach ($categories as $category):
array_push($cat_ids, $category->term_id);
endforeach;
endif;
$current_post_type = get_post_type($post_id);
$query_args = array(
'category__in' => $cat_ids,
'post_type' => $current_post_type,
'post_not_in' => array($post_id),
'posts_per_page' => '10'
);
$related_cats_post = new WP_Query( $query_args );
if($related_cats_post->have_posts()):
while($related_cats_post->have_posts()): $related_cats_post->the_post(); ?>
<div class="card text-gray height-100p shadow-v2">
<a href="<?php the_permalink(); ?>">
<img class="card-img-top" src="<?php echo get_field('imagem_do_curso') ?>" alt="">
</a>
<div class="p-4">
<a href="<?php the_permalink(); ?>" class="h6">
<?php the_title(); ?>
</a>
<button class="btn btn-primary btn-sm btn-pill" style="color: #191B31!important">
+ <?php echo get_field('quantidade_de_alunos_formados') ?> Alunos formados
</button>
</div>
</div>
<?php endwhile;
// Restore original Post Data
wp_reset_postdata();
endif;
}