如果我单击类别,则在WordPress的同一页上明智地过滤类别 塑料,我想要结果塑料产品
例如产品类别
1。塑料 2.金属 3.银 显示图像 enter image description here
发布div
<?php
global $post;
$myposts = get_posts(
array(
'post_type' => 'product',
'numberposts' => '999',
'orderby' => 'menu_order',
'order' => 'ASC'
)
);
?>
侧边栏div
<?php
global $post;
$curVal = "";
$myposts = get_posts(
array(
'post_type' => 'product',
'numberposts' => '999',
'orderby' => 'product_category',
'order' => 'ASC'
)
);
?>
<ul>
<?php
foreach($myposts as $post){
if($curVal != get_field('franchise_category')) { ?>
<li>
<a href="<?php echo home_url( $wp->request ); ?>?cat=<?php echo get_field('product_category'); ?>">
<?php echo get_field('product_category'); ?>
</a>
</li>
<?php }$curVal = get_field('product_category');} ?>
</ul>
答案 0 :(得分:0)
如果要使用此查询获取所有帖子,请使用第一个:
'numberposts' => -1,// this will return all available, right now you are passing a string 999 - '999'
第二-您不是setting up your post数据,restoring context of the template tags则尝试此操作:
foreach ( $myposts as $post ) : setup_postdata( $post );
...
...
endforeach;
wp_reset_postdata();
编辑代码并查看结果。