过去两周我一直在努力解决一个问题,但我仍然没有找到任何解决方案<让我先解释一下我的问题:
我有两种自定义帖子类型:一种是football_fixture
其次是football_league
.<这两个CPT有两个共同的分类法:一个是“competition
” 第二个是“session
”.这两种分类法也有术语;例如:laliga、EPL、Seria和2016-17、2015-16<现在我想要什么:
在我的football_league
发布,我想显示的内容football_fixture
根据以下条件:
1)英寸football_league
post如果我选择竞争分类法和会话分类法,那么它将只显示football_fixture
有这些条款的帖子。有关更多说明,请参见图:假设我已经发布了5篇带有竞争条款的football\\u fixture帖子”
laliga
” 和session
“期限”2026-17
”.
现在如果我发布football_league
使用发布competition
“条款”laliga
” 和session
“期限”2026-17
” 然后它会显示5个football_fixture
’s 5立柱。有可能吗?我使用了以下代码:
如何在条款相同的另一篇文章内容中显示另一篇文章内容?
1 个回复
SO网友:bdtheme
我自己解决了这个问题:
我所做的是:
首先创建single-football_league.php template
在此处,我放置了以下代码:
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( \'content-parts/content\', \'league\' ); ?>
<?php endwhile; ?>
第二:英寸content-league.php
, 我放置了以下代码,它可以工作:$terms = wp_get_post_terms( $post->ID, array(\'competition\', \'session\') );
$term_slugs = wp_list_pluck( $terms, \'slug\' );
$season = wp_get_post_terms( $post->ID, \'session\' );
$season_slugs = wp_list_pluck( $terms, \'slug\' );
$args = array(
\'post_type\' => array( \'football_fixture\' ), // profile and letter are CPTs
\'tax_query\' => array(
array(
\'taxonomy\' => \'competition\',
\'field\' => \'slug\',
\'terms\' => $term_slugs
),
array (
\'taxonomy\' => \'session\',
\'terms\' => $season_slugs,
\'field\' => \'slug\')
)
);