我有两个自定义帖子类型“场馆”和“活动”。。如何查询“场馆”,然后显示具有相同分类法值的所有“事件”。
<?php
$taxonomy = \'venue-name\';
$param_type = \'venue-name\';
$tags = wp_get_post_terms( $post->ID , $taxonomy, $tax_args);
if ($tags) {
foreach ($tags as $tag) {
$args = array(
\'post_type\' => \'venues\',
"$param_type" => $tag->slug,
\'post__not_in\' => array($post->ID),
\'showposts\'=> 1,
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
?>
SO网友:s_ferdie
没有测试以下代码,但它应该可以帮助您朝着正确的方向前进。
$args = array(
\'post_type\' => array(\'venues\', \'events\'),
\'post__not_in\' => array($post->ID),
\'tax_query\' => array(
array(
\'taxonomy\' => \'custom_taxonomy\',
\'field\' => \'slug\',
\'terms\' => $tags,
)
)
);