问题描述
我会用选定的分类过滤我拥有的帖子,分类参数在 url 中,但继续向我显示所有帖子而不是过滤帖子 我想要一个过滤器,这是我的代码,问题出在哪里?
$currentPost = new Timber\Post();
$post_type = 'cataloghi';
$number_posts = -1;
$MetaOrder = 'name';
$template = 'parts/catalog-widget.twig';
$MetaOrderDirection = 'DESC';
// Estrazione dei cataloghi
$catalogs = new Timber\PostQuery(array(
'post_type' => $post_type,'post_status' => 'publish','numberposts' => $number_posts,'orderby' => $MetaOrder,'order' => $MetaOrderDirection
));
//Gestione filtri
$paramSearch = $_GET;
$catalogs['tax_query'] = array();
//Filtro per categoria-catalogo
if(isset($paramSearch['ct'])) {
$data['search_data']['category'] = $paramSearch['ct'];
if($paramSearch['ct'] != 'all' ) {
$catalogs['tax_query'][] = array(
'taxonomy' => 'categoria-'.$post_type,'field' => 'slug','terms' => $paramSearch['ct']
);
}
}
$allPosts = new Timber\PostQuery($catalogs);
$data['all_posts'] = $catalogs;
var_dump($catalogs['tax_query']);
//Estrazione dei dati per popolare i filtri
$data['categories'] = Timber::get_terms(array(
'taxonomy' => 'categoria-'.$post_type,'hide_empty' => true,'orderby' => 'name','order' => 'DESC'
));
//Link pagina corrente
$data['current_post_link'] = $currentPost->link;
wp_reset_query();
if(!empty($template)){
Timber::render( $template,$data);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)