使用 Wordpress 自定义分类过滤 [英] Custom Taxonomy Filtering with Wordpress

查看:36
本文介绍了使用 Wordpress 自定义分类过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试解决这个问题三天了,甚至使用了本网站上的解决方案.我仍然无法正常工作.

Ive been trying to figure this out for three days now, even using solutions on this site. I still cant get this working.

我有一个 wordpress 循环,它使用过滤器按帖子类型显示帖子.现在帖子类型被称为案例研究",因此显示了类型案例研究中的所有帖子.

I have a wordpress loop that uses a filter to show posts by post type. Now the post type is called "case-studies" Thus all the posts in the type case studies are shown.

但是我需要在这个循环中隐藏一个特定的分类术语.分类法称为部门",术语为医疗保健".我尝试了各种组合,但仍然无法得到这个.我非常需要这个.任何能提供帮助的人都会挽救我的生命.

But i need to hide a specific taxonomy term from this loop. The taxonomy is called "sectors" and the term is "healthcare". Ive tried all manner of combinations but still cant get this. I need this pretty urgent. Anyone who can help would save my life.

这是查询和循环

<?php
// The Query
$the_query = new WP_Query( 'post_type=case-studies&posts_per_page=-1' );

// The Loop
while ( $the_query->have_posts() ) :
    $the_query->the_post(); 


?>

推荐答案

    $args = array(
    'post_type' => 'case-studies',
    'tax_query' => array(
        array(
            'taxonomy' => 'sectors',
            'field' => 'slug',
            'terms' => array('comercial', 'personal', 'etc') //excluding the term you dont want.
        )
    )
);
$query = new WP_Query( $args );

我没有尝试,但您可以只调用您想要的术语进行查询,您可以之前填充列出分类法中的所有术语并排除您想要的术语的术语数组,我认为这有点hacky 这应该是另一种直接的方法,但请尝试一下,因为这是生死攸关的案例 =).

I dind´t try it but you could just make a query calling only the terms you want, you could previously populate the terms array listing all the terms on the taxonomy and excluding the one you want, i think this is a little hacky it should be another straight forward way to do it but give it a try since it is a case of life or dead =).

来源:http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

这篇关于使用 Wordpress 自定义分类过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆