How to Show Related Posts For custom post Type in WordPress

How-to-Show-related-Posts-For-custom-post-Type-in-Wordpress

This code is used to fetch Related Posts in your custom post Type, This code adds your function.php file WordPress.

Display the related post of the article is very easy and you can add related posts list to your blog without using any plugin.

<?php

$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5,'post_type' => 'mjob_post', 'post__not_in' => array($post->ID) ) );
 if( $related ) foreach( $related as $post ) {
 setup_postdata($post); ?>
   <li>
   <?php  the_post_thumbnail(); ?>
   <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>

   </li>

 <?php }

wp_reset_postdata();

?>
Learn Tutorials Point
We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact us

Fill in the form below or give us a call and we'll contact you. We endeavour to answer all enquiries within 24 hours on business days.