我有这段代码可以使用,但它只显示5个帖子(带有自定义分类),其中应该是7.如果我点击标记网址,它会显示7个注册表,所以问题就出现了#39 ; s在此代码及其查询中。我已经尝试过nopaging = true,posts_per_page = -1 numberposts = -1并将最后两个设置为固定数字,如7或999;但这些选项似乎都无法解决问题。
希望有人可以帮助我。感谢。
add_shortcode('gpp_prod', function( $atts, $content = null ){
ob_start();
$atts = shortcode_atts(
array(
'category' => '0'
), $atts);
extract($atts);
$args = array(
'post_type'=>'gpp_prod',
'orderby' => 'title',
'order' => 'ASC'
);
if($category > 0 ){
$args['tax_query'] = array(
array(
'posts_per_page' => -1,
'taxonomy' => 'cat_prod',
'field' => 'term_id',
'nopaging' => true,
'terms' => $category
)
);
}
?>
<?php $products = get_posts($args);
$termt = get_term($category, 'cat_prod');
<div class="prod-cats">
<h1><?php echo $termt->name;?></h1>
<?php if(count($products)>0) {
foreach ($products as $key => $value) { ?>
<div class="prod-group">
<div class="prod-title"><?php echo do_shortcode( $value->post_title); ?></div>
<div class="prod-low">
<div class="prod-image"><img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($value->ID)); ?>"/></div>
<div role="tabpanel" class="prod-info">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#tab-1-<?php echo $value->ID?>" aria-controls="home" role="tab" data-toggle="tab">Desc</a></li>
<li role="presentation"><a href="#tab-2-<?php echo $value->ID?>" aria-controls="profile" role="tab" data-toggle="tab">Specs</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="tab-1-<?php echo $value->ID?>"><?php echo do_shortcode( $value->post_content); ?></div>
<div role="tabpanel" class="tab-pane" id="tab-2-<?php echo $value->ID?>"><?php $meta_value = get_post_meta( $value->ID, 'meta-text', false );
if( !empty( $meta_value ) ) {
echo $meta_value[0];
} else {
echo 'No specs available';
}
?>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<?php
}
?>
</div>
<?php
wp_reset_postdata();
return ob_get_clean();
});
答案 0 :(得分:0)
posts_per_page需要进入$ args数组,而不是$ args [&#39; tax_query&#39;]。设置posts_per_page = -1时,nopaging也是多余的。试试这个:
$args = array(
'post_type'=>'gpp_prod',
'orderby' => 'title',
'order' => 'ASC'
'posts_per_page' => -1,
);
if($category > 0 ){
$args['tax_query'] = array(
array(
'taxonomy' => 'cat_prod',
'field' => 'term_id',
'terms' => $category
)
);
}