Php 我想在wordpress中过滤同一页面上的分类帖子
如果单击“类别”,则在WordPress中的同一页上按post-wise筛选类别 我要塑料制品 例如产品类别 1.塑料 2.金属 3.银牌 显示图像 邮政司Php 我想在wordpress中过滤同一页面上的分类帖子,php,wordpress,Php,Wordpress,如果单击“类别”,则在WordPress中的同一页上按post-wise筛选类别 我要塑料制品 例如产品类别 1.塑料 2.金属 3.银牌 显示图像 邮政司 <?php global $post; $myposts = get_posts( array( 'post_type' => 'product', 'numberposts' => '999', 'orderby' => 'menu_order',
<?php
global $post;
$myposts = get_posts(
array(
'post_type' => 'product',
'numberposts' => '999',
'orderby' => 'menu_order',
'order' => 'ASC'
)
);
?>
边栏分区
<?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>
-
1st如果您想通过此查询获取所有帖子,请使用:
'numberposts' => -1,// this will return all available, right now you are passing a string 999 - '999'
第二-您不是数据,请尝试以下方法:
foreach ( $myposts as $post ) : setup_postdata( $post );
...
...
endforeach;
wp_reset_postdata();
编辑代码并查看结果 你的问题是什么?请说清楚。