admin管理员组文章数量:1440470
everybody. Related posts by taxonomies does not work , what could be the reason?
$tax_IDs = array();
foreach ($tags as $tag) {
$tax_IDs[] = $tag->ID;
}
$args = array(
'post_type' => 'films',
'post__not_in' => array($post->ID),
'showposts'=> 3,
'tax_query' => array(
array(
'taxonomy' => 'actors',
'field' => 'id',
'terms' => $tax_IDs
)
)
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '<div class="related-slider">';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div><?php the_title(); ?></div>
<?php
}
echo '</div>';
}
wp_reset_query();
everybody. Related posts by taxonomies does not work , what could be the reason?
$tax_IDs = array();
foreach ($tags as $tag) {
$tax_IDs[] = $tag->ID;
}
$args = array(
'post_type' => 'films',
'post__not_in' => array($post->ID),
'showposts'=> 3,
'tax_query' => array(
array(
'taxonomy' => 'actors',
'field' => 'id',
'terms' => $tax_IDs
)
)
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '<div class="related-slider">';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div><?php the_title(); ?></div>
<?php
}
echo '</div>';
}
wp_reset_query();
Share
Improve this question
edited Mar 23, 2019 at 0:45
starspro
asked Mar 23, 2019 at 0:13
starsprostarspro
33 bronze badges
1 Answer
Reset to default 0Your tax_query is using an invalid field
type. Try:
$args = array(
'post_type' => 'films',
'post__not_in' => array($post->ID),
'showposts'=> 3,
'tax_query' => array(
array(
'taxonomy' => 'actors',
'field' => 'term_id',
'terms' => $tax_IDs
)
)
);
See the Taxonomy Parameters of WP_Query for more options if that doesn't wok.
本文标签: custom taxonomyRelated posts by taxonomies does not workwhat could be the reason
版权声明:本文标题:custom taxonomy - Related posts by taxonomies does not work , what could be the reason? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745664509a2669209.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论