我正在尝试在 Wordpress 的单个帖子页面中按分类显示相关帖子。我使用以下代码来显示同一类别中的帖子,但不是相同的自定义分类。我需要使用的自定义分类是 product_cat
<?php
global $post;
$categories = get_the_category();
$category = $categories[0];
$cat_ID = $category->cat_ID;
$loop = new WP_Query( array( 'post_type' => 'product','post__not_in' => array($post->ID), 'category' => $cat_ID ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>
<?php endwhile; ?>
如何调整当前代码?