Showing related post for custom taxonomy

Question

I need to edit single.php file in order to show related post for a custom taxonomy I’ve already created (named ‘tag-italia).

Can anyone help me to achieve that?

For the “general” related post by tag I’m using this code, which shows the related post only if there’s something to show:

<div>
<?php $orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=>4, // Number of related posts that will be shown.
'ignore_sticky_posts'=>1
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {

echo '<div><h3 class="titolo-related">Potrebbe interessarti:'; the_tags(' #', $sep = ' | #'); echo'</h3>'?>

<?php while( $my_query->have_posts() ) {
$my_query->the_post(); ?>
<div>
<div><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a></div>
<div>
</br><h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt() ?>
</div>
</div>

I’ve tried to customize this code without any success.

Thanks in advance!

0
Luca 3 years 2020-08-24T11:10:22-05:00 0 Answers 46 views 0

Leave an answer

Browse
Browse