Today I ran into a problem, I need to implement a related post on the blog detail page and found this solution.
And nonetheless, It's better to fix the thing with some bunch of code rather than uploading one more bulky plugin on your website that will end up making your site heavy.
Just follow the steps below and avoid heading up into any malicious or bulky plugin for this particular problem from now on forever.
Step 1: Get the id of current post in starting of single.php like following
<?php $do_not_duplicate = $post->ID; ?>
Step 1: Now in your related post query add the following
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'post__not_in' => array( $do_not_duplicate ),
'order' => 'ASC',
);
$related_query = new WP_Query($args);
while ( $related_query->have_posts() ): $related_query->the_post();
?>
Now Cheers !😊
Comments
Post a Comment