admin管理员组文章数量:1415655
I have a custom post type called 'brand', with a taxonomy of 'brand-categories'. try as I might, I cannot find a way to display a list of posts in the current taxonomy. can anyone help?
<?php
function List_Brands_of_Category(){
$terms = wp_get_post_terms( $post->ID, 'brand-categories');
foreach ( $terms as $term ) {
echo "$term->ID";
}
$args = array(
'post_type' => 'brand',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'brand-categories',
'field' => 'ID',
'terms' => array($term->term_id)
)
),
);// end args
$query = new WP_Query($args); ?>
<?php
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
echo 'Brand';
$query->the_post();
}
}
else {?>
<p><?php _e( 'Sorry, no posts matched your criteria.' );
}
?></p>
<?php
}
function DMBrandofCategory_Cleanse() {
ob_start();
List_Brands_of_Category();
return ob_get_clean();
}
add_shortcode('WC_BOC', 'DMBrandofCategory_Cleanse');
?>
I have a custom post type called 'brand', with a taxonomy of 'brand-categories'. try as I might, I cannot find a way to display a list of posts in the current taxonomy. can anyone help?
<?php
function List_Brands_of_Category(){
$terms = wp_get_post_terms( $post->ID, 'brand-categories');
foreach ( $terms as $term ) {
echo "$term->ID";
}
$args = array(
'post_type' => 'brand',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'brand-categories',
'field' => 'ID',
'terms' => array($term->term_id)
)
),
);// end args
$query = new WP_Query($args); ?>
<?php
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
echo 'Brand';
$query->the_post();
}
}
else {?>
<p><?php _e( 'Sorry, no posts matched your criteria.' );
}
?></p>
<?php
}
function DMBrandofCategory_Cleanse() {
ob_start();
List_Brands_of_Category();
return ob_get_clean();
}
add_shortcode('WC_BOC', 'DMBrandofCategory_Cleanse');
?>
Share
Improve this question
edited Sep 13, 2019 at 9:28
Chetan Vaghela
2,4084 gold badges10 silver badges16 bronze badges
asked Sep 13, 2019 at 9:23
Captain DandoCaptain Dando
1339 bronze badges
1 Answer
Reset to default 0$args = array(
'post_type' => 'brand',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'brand-categories',
'field' => 'name',
'terms' => get_queried_object()
)
),
);// end args
本文标签: pluginsCan39t get custom posts of taxonomy to show
版权声明:本文标题:plugins - Can't get custom posts of taxonomy to show 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745161854a2645474.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论