Cara membuat Related Post untuk Custom Post Type

October 20, 2018 Artikel,Snippets,Tips dan Trik,WordPress Kholis Muhaimin

WordPress juga mempunya fitur menampilkan Related Post berdasarkan Custom Post Type, Post tpye ini tentu berbeda dengan Post lainnya.

<?php
    'order' => 'DESC',
    'orderby' => 'ID',
    'post_type' => $current_post_type,
    'post__not_in' => array( $post->ID )
);
// Create the related query
$rel_query = new WP_Query( $args );
// Check if there is any related posts
if( $rel_query->have_posts() ) : 
?>
<h1 class="recent">Related</h1>
<div class="related">
<ul class="group">
<?php // The Loop while ( $rel_query->have_posts() ) :
        $rel_query->the_post();
?>

<li>
 <a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark"></a>
<div>           
<h1 class="entry-title"><?php the_title() ?></h1>
<?php the_time('F j, Y'); ?>
<?php the_excerpt(); ?>
</div>
        </li>
<?php endwhile; ?>
    </ul>
<!-- .group -->
</div>
<!-- #related -->
<?php endif; // Reset the query wp_reset_query(); ?>

163 total views, 3 views today

Facebooktwittergoogle_plusredditpinterestlinkedinmail