我已经玩了很久了,因为某种原因,我不能让它工作。
这是来自自定义帖子类型的单个帖子页面中。。。
基本上,我是通过使用get\\u the\\u术语获得自定义帖子类型的类别,然后通过foreach将其很好地输入到字符串中。
然后我使用WP\\u查询进行检索,但我认为我的逻辑有误。
这就是我所拥有的
// post types query
if ( have_posts() ) : while ( have_posts() ) :the_post();
// getting the categories
$categorynames = \'\';
$getcategory = get_the_terms($post->ID, \'custompostnamehere-categories\');
foreach($getcategory as $t){ $categorynames .= $t->term_id.\' ,\';}
if (substr($categorynames, -1) == \',\') {
$categorynames = substr($categorynames, 0, -1);
}
// end of post type query
endwhile; endif; wp_reset_query();
//starting new query to get related posts within the same categories
$args = array(
\'post_type\' => \'custompostnamehere\',
\'cat\' => $categorynames,
\'posts_per_page\' => 20
);
$q = new WP_Query($args);
// retrieving the data
while($q->have_posts()){
}
有人能告诉我我做错了什么吗。谢谢