Display prev / next posts links from the same category with thumbnails in WordPress

So I asked ChatGPT and it comes with a working solution for me:

    <?php 
    $prev_post = get_previous_post(true, '', 'listing_category');
    if (!empty($prev_post)) : ?>
        <a href="<?php echo get_permalink($prev_post->ID); ?>">
            <?php echo get_the_post_thumbnail($prev_post->ID, 'thumbnail'); ?>
            << <?php echo esc_html($prev_post->post_title); ?>
        </a>
    <?php endif; ?>
</div>

<div class="next-post-link">
    <?php 
    $next_post = get_next_post(true, '', 'listing_category');
    if (!empty($next_post)) : ?>
        <a href="<?php echo get_permalink($next_post->ID); ?>">
            <?php echo get_the_post_thumbnail($next_post->ID, 'thumbnail'); ?>
            <?php echo esc_html($next_post->post_title); ?> >>
        </a>
    <?php endif; ?>
</div>

Explanation:

get_previous_post($in_same_term, $excluded_terms, $taxonomy): Retrieves the previous post object. The $in_same_term argument ensures that the post is from the same category or taxonomy term (listing_category in your case).

get_next_post($in_same_term, $excluded_terms, $taxonomy): Similarly, this retrieves the next post object.

get_the_post_thumbnail($post_id, $size): Fetches the post thumbnail for the specified post ID. The size ‘thumbnail’ is used, but you can change this to any other size, like ‘medium’ or ‘large’.

get_permalink($post->ID): Gets the URL for the post.

Notes:
Ensure that your posts have featured images (thumbnails) set, as this code relies on them.
You can style the output as needed by adding custom CSS.
This code should give you the desired result, displaying the previous and next posts’ titles along with their thumbnails, all within the same taxonomy category.

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino