• Skip to main content
  • Skip to primary sidebar

WordPress, Genesis Framework and Storefront customization tutorials

  • Archive
    • Free
    • Premium
  • Blog
  • About
  • Contact
  • Newsletter
  • Login
Home » How to loop related posts by tags

How to loop related posts by tags

<?php

$tags = wp_get_post_tags($post->ID);

if ($tags) {
    
    echo '<h3>Kapcsolódó bejegyzések</h3>';
    
    $first_tag = $tags[0]->term_id;
    
    $args=array(
        'tag__in' => array($first_tag),
        'post__not_in' => array($post->ID),
        'posts_per_page'=>5,
        'caller_get_posts'=>1
    );
    
    $my_query = new WP_Query($args); ?>
    
    <div class="row">
    
    <?php if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?>
        
        <div class="col-md-4">
            <div class="card">
                     <div class="item-hover circle effect13 top_to_bottom">
                         <a href="<?php the_permalink(); ?>">
                              <div class="card-body">
                                <h3 class="card-title"><?php the_title(); ?></h3>
                                <p class="readmore"><i class="fas fa-angle-right"></i> <?php include('translate/tovabb.php'); ?></p>
                              </div>
                              <div class="info">
                                    <div class="info-back home-posts">
                                        <h3 class="label"><?php the_title(); ?></h3>
                                        <p class="readmore-postsback"><i class="fas fa-angle-right"></i><?php include('translate/tovabb.php'); ?></p>
                                    </div>
                              </div>
                      </a>
                    </div>
                </div>
            </div>

    <?php
    endwhile;
    }
    ?>
    </div>
    <?php
    wp_reset_query();
}
?>

Filed Under: Free Tagged With: PHP

About Gabor Flamich

I'm a web developer and designer based in Budapest, Hungary. In recent years, I've documented hundreds of solutions I came across during development. This site is an archive for useful code snippets on WordPress, Genesis Framework and WooCommerce. If You have any questions related to WordPress development, get in touch!

Primary Sidebar

Gabor Flamich

Hi! I'm Gabor.
I write tutorials on WordPress and WooCommerce.

MacBook

12 Essential Snippets for Genesis Developers

Subscribe to my Newsletter to view my basic collection of Genesis snippets that I use for my projects!

Sign Up for Free
  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
UpdraftPlus Premium

Tags

ACF Ajax Analytics API Bootstrap Breadcrumb category CPT CSS fetch FSE Genesis Google Maps Gutenberg HTML Isotope JavaScript jQuery loop Map Menu Parallax PHP Rest API SASS SEO SQL Storefront SVG tab tag manager tags Taxonomy Tool upsell Webpack Wholesale WooCommerce WordPress WPML

Disclosure: Some of the links in this site are affiliate links. I will be paid a commission if you use this link to make a purchase.

  • Privacy Policy / Terms of Service
© 2025 WP Flames - All Right Reserved