Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add related posts with thumbnails by placing a secondary post query in your single-post template, choosing a rule for what counts as “related,” and outputting each result’s title and featured image. This code-based approach uses WordPress’s built-in functions; it requires a theme that supports post thumbnails and needs adapting to your theme’s template, taxonomy, and design.

Before you add the code

  • Use a classic theme template. The examples below are for PHP-based single-post templates. Block themes may use a different template workflow, so these snippets may not fit without adapting the theme.
  • Choose a relevance rule. Shared categories are a straightforward starting point. Shared tags or a custom taxonomy can make the matches narrower. WordPress can retrieve posts using query criteria, but it cannot decide your editorial definition of “related.”
  • Confirm featured-image support. A theme generally needs to declare add_theme_support( 'post-thumbnails' ) for the featured-image controls to appear in the editor. The theme should register support in its setup callback on after_setup_theme, before init. See WordPress’s featured image documentation and the add_theme_support() reference.
  • Make a backup and use a child theme or another update-safe customization method. Editing a parent theme directly risks losing the change when the theme is updated.

If you are developing your own theme and thumbnails are not enabled, register support in its setup function, for example:

function mytheme_setup() {
    add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'mytheme_setup' );

Do not add a second setup function blindly if your theme already has one; add the support declaration to the theme’s existing setup logic instead.

Choose how WordPress will find related posts

The query needs a concrete relationship rule. This example finds published posts in any category shared with the current post. It excludes the current post and limits the result to four entries:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
<?php
$current_id = get_queried_object_id();
$category_ids = wp_get_post_categories( $current_id );

if ( $category_ids ) {
    $related_posts = get_posts( array(
        'post_type'           => 'post',
        'post_status'         => 'publish',
        'posts_per_page'      => 4,
        'post__not_in'        => array( $current_id ),
        'category__in'        => $category_ids,
        'ignore_sticky_posts' => true,
    ) );
}
?>

category__in means a result can match any category in the current post’s category list. If that is too broad, use a tag or custom-taxonomy rule instead. The query parameters and retrieval functions are documented in the WordPress get_posts() reference.

For tags, retrieve the current post’s tag IDs and use the corresponding tag query argument, such as tag__in. For a custom taxonomy, use a tax_query that names the taxonomy and terms your site uses. Make sure the taxonomy is registered for the post type being queried.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Render titles and thumbnails with get_posts()

Place the query and output in the appropriate single-post template, where the related-post section should appear. Add this markup after the query above:

<?php if ( ! empty( $related_posts ) ) : ?>
    <section class="related-posts" aria-labelledby="related-posts-title">
        <h2 id="related-posts-title">Related posts</h2>
        <ul>
            <?php foreach ( $related_posts as $related_post ) : ?>
                <?php if ( has_post_thumbnail( $related_post->ID ) ) : ?>
                    <li>
                        <a href="<?php echo esc_url( get_permalink( $related_post->ID ) ); ?>">
                            <?php echo get_the_post_thumbnail( $related_post->ID, 'medium' ); ?>
                            <span><?php echo esc_html( get_the_title( $related_post->ID ) ); ?></span>
                        </a>
                    </li>
                <?php endif; ?>
            <?php endforeach; ?>
        </ul>
    </section>
<?php endif; ?>

The explicit post ID in has_post_thumbnail(), get_the_post_thumbnail(), and get_the_title() matters: it ensures each card uses the related result rather than the current post. This version omits results without a featured image. If every result should display a visual, replace that condition with a designed fallback image or another deliberate placeholder.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Use CSS in your theme to turn the list into the layout you want. The PHP supplies the content and links; it does not prescribe a grid, card style, spacing, or responsive behavior.

Choose an image size that fits the layout

The second argument to get_the_post_thumbnail() selects a registered image size. WordPress documents these defaults in its featured image guide:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Size Documented default dimensions Typical consideration
thumbnail 150 × 150 pixels maximum Small cards; the default is cropped to a square.
medium 300 × 300 pixels maximum Compact cards; the image retains its proportions within the maximum.
medium_large 768 pixels wide maximum, no height limit Wider display areas.
large 1024 × 1024 pixels maximum Larger cards or layouts with more image area.
full Full uploaded image dimensions Use only when the design needs the original size; it may be unnecessarily large for a small card.

These are documented defaults, and the dimensions can be changed in WordPress Media settings. Themes can also register custom image sizes. If you add a custom size, remember that registering it does not automatically create that size for images already uploaded; existing thumbnails may need to be regenerated using an appropriate method. The WordPress thumbnail-size reference documents size configuration.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use WP_Query instead

get_posts() returns an array and suits a simple list. A separate WP_Query is a good choice when you want to write the output as a conventional WordPress loop or need loop-oriented query behavior. WordPress specifically recommends a new WP_Query or get_posts() for secondary listings such as related posts; see its documentation for query_posts().

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
<?php
$current_id = get_queried_object_id();
$category_ids = wp_get_post_categories( $current_id );

if ( $category_ids ) {
    $related_query = new WP_Query( array(
        'post_type'           => 'post',
        'post_status'         => 'publish',
        'posts_per_page'      => 4,
        'post__not_in'        => array( $current_id ),
        'category__in'        => $category_ids,
        'ignore_sticky_posts' => true,
    ) );

    if ( $related_query->have_posts() ) : ?>
        <section class="related-posts" aria-labelledby="related-posts-title">
            <h2 id="related-posts-title">Related posts</h2>
            <ul>
                <?php while ( $related_query->have_posts() ) : $related_query->the_post(); ?>
                    <?php if ( has_post_thumbnail() ) : ?>
                        <li>
                            <a href="<?php the_permalink(); ?>">
                                <?php the_post_thumbnail( 'medium' ); ?>
                                <span><?php the_title(); ?></span>
                            </a>
                        </li>
                    <?php endif; ?>
                <?php endwhile; ?>
            </ul>
        </section>
    <?php endif;

    wp_reset_postdata();
}
?>

wp_reset_postdata() restores the global post data after the secondary loop. Do not use query_posts() for this feature: it changes the main query rather than creating a separate listing.

Common problems to check

  • No featured-image controls in the editor: verify that the active theme declares post-thumbnail support and that its setup callback runs on after_setup_theme.
  • No related posts appear: confirm the current post has terms in the taxonomy you query, and that other published posts share those terms.
  • The current post appears in the list: check that the current post ID is passed to post__not_in.
  • Cards appear without images or some results disappear: the sample omits posts without featured images. Add featured images or implement a fallback if all cards must have a visual.
  • Images look too small, too large, or cropped unexpectedly: choose a size that fits the card and account for the selected size’s crop behavior and your theme’s registered sizes.
  • The main template behaves strangely after the related section: if using WP_Query, make sure wp_reset_postdata() runs after the secondary loop.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.