escort sitesi alanya bayan escort manavgat bayan escort fethiye bayan escort kemer bayan escort didim bayan escort çanakkale bayan escort Aydın bayan escort muğla bayan escort tekirdağ bayan escort manisa bayan escort balıkesir bayan escort trabzon bayan escort elazığ bayan escort ordu bayan escort kütahya bayan escort ısparta bayan escort rize bayan escort maraş bayan escort yalova bayan escort giresun bayan escort yozgat bayan escort tokat bayan escort şanlıurfa bayan escort sivas bayan escort batman bayan escort erzurum bayan escort sinop bayan escort kırşehir bayan escort karaman bayan escort kırıkkale bayan escort bolu bayan escort amasya bayan escort niğde bayan escort uşak bayan escort edirne bayan escort çorum bayan escort osmaniye bayan escort zonguldak bayan escort van bayan escort erzincan bayan escort istanbul masaj ankara masaj izmir masaj bursa masaj antalya masaj adana masaj konya masaj şanlıurfa masaj gaziantep masaj kocaeli masaj mersin masaj diyarbakır masaj hatay masaj manisa masaj kayseri masaj samsun masaj balıkesir masaj maraş masaj van masaj aydın masaj tekirdağ masaj sakarya masaj denizli masaj muğla masaj adıyaman masaj afyon masaj ağrı masaj aksaray masaj amasya masaj ardahan masaj artvin masaj bartın masaj batman masaj bayburt masaj bilecik masaj bingöl masaj bitlis masaj bolu masaj burdur masaj çanakkale masaj çankırı masaj çorum masaj düzce masaj edirne masaj elazığ masaj erzincan masaj erzurum masaj eskişehir masaj giresun masaj gümüşhane masaj ığdır masaj ısparta masaj karabük masaj karaman masaj kastamonu masaj kilis masaj kırıkkale masaj kırklareli masaj kırşehir masaj uşak masaj kütahya masaj malatya masaj mardin masaj nevşehir masaj niğde masaj ordu masaj trabzon masaj osmaniye masaj rize masaj siirt masaj sinop masaj sivas masaj tokat masaj kayseri escort kayseri escort kıbrıs escort kilis escort konya escort konya escort konya escort malatya escort malatya escort malatya escort manisa escort gaziantep escort van escort tunceli escort bursa escort sivas escort siirt escort şanlıurfa escort bilecik escort samsun escort çanakkale escort istanbul escort ankara escort izmir escort izmir escort bursa escort antalya escort antalya escort adana escort kocaeli escort konya escort mersin escort şanlıurfa escort samsun escort diyarbakır escort hatay escort manisa escort balıkesir escort gaziantep escort sakarya escort tekirdağ escort kayseri escort eskişehir escort aydın escort van escort denizli escort kahramanmaraş escort izmit escort trabzon escort adıyaman escort afyon escort erzurum escort ordu escort bodrum escort bodrum escort malatya escort elazığ escort tokat escort sivas escort muğla escort aksaray escort amasya escort niğde escort batman escort kütahya escort çanakkale escort çankırı escort çorum escort düzce escort hakkari escort edirne escort yozgat escort zonguldak escort bingöl escort yalova escort uşak escort sinop escort şırnak escort rize escort muş escort nevşehir escort osmaniye escort bolu escort mardin escort kırşehir escort kastamonu escort giresun escort kırıkkale escort ısparta escort karabük escort karaman escort kibris escort hatay escort ağrı escort afyon escort antalya escort antalya escort ardahan escort artvin escort ankara escort balıkesir escort bartın escort ankara escort bayburt escort bitlis escort istanbul escort burdur escort
How to Show Related Posts for Custom Post Type in WordPress

How to Show Related Posts for Custom Post Type in WordPress

Display Related posts in WordPress it’s very useful to drive the audience of your website. Using WordPress we can show the related posts of a specific post type. To display the related post of the contents it’s very easy and you can display related posts to the blog page without using any plugin.

To show related posts for custom post type, all the posts needs to be achieved by custom taxonomy-terms of the custom post type. In this tutorial, we will show you how to display the related posts for custom post type in WordPress. No need to use any extra plugin for showing related posts for custom post type in WordPress.

There default post details page is single.php. But when when we create custom post type in that case we need to create another php file for the custom post type. The php file should be like this single-custom_post_type_name.php. Open this file and add this following code to display related posts for custom post type in WordPress.

//get the taxonomy terms of custom post type
$customTaxonomyTerms = wp_get_object_terms( $post->ID, 'your_taxonomy_name', array('fields' => 'ids') );

//query arguments
$args = array(
'post_type' => 'your_custom_post_type_name',
'post_status' => 'publish',
'posts_per_page' => 6,
'orderby' => 'rand',
'tax_query' => array(
'taxonomy' => 'your_custom_taxonomy_name',
'field' => 'id',
'terms' => $customTaxonomyTerms
'post__not_in' => array ($post->ID),

//the query
$relatedPosts = new WP_Query( $args );

//loop query
if($relatedPosts->have_posts()){ ?>
<div class="post_repeat">
<?php while($relatedPosts->have_posts()){
<div class="content"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li></div>
} ?>
<?php }else{
//no posts found

//restore post data

Here custom post type declared in post_type and custom taxonomy term of that post type in taxonomy. Also, specified the number of related posts in posts_per_page that you want to display.