Wordpress:在自定义分类中重新搜索特定自定义类别的帖子

时间:2010-05-13 10:11:20

标签: wordpress

我可以通过调用WP_Query

来检索自定义类别中的所有帖子
$q = new WP_Query(array( 'taxonomy' => 'jh-portfolio-category',
                          'term' => 0, 'post_type' => 'jh-portfolio' ));

但是,假设在jh-portfolio-category分类中我定义了一些子类别,如何指定我希望从特定子类别中获得帖子?将'term'属性更改为wp_term_taxonomy中提供的term_id似乎不起作用。该分类中的所有帖子仍在列出。

3 个答案:

答案 0 :(得分:0)

我不确定这对你有帮助。我有一个类似的问题,我试图get_posts是一个自定义的post_type和分类。

您的post_type名称为jh-portfolio。您的分类法称为jh-portfolio-category。您没有在帖子中指定术语的名称,因此我们将其称为foobar。你的get_posts或query_posts函数如下所示:

  get_posts("post_type=jh-portfolio&jh-portfolio-category=foobar");
query_posts("post_type=jh-portfolio&jh-portfolio-category=foobar");

我不确定这会如何转化为WP_Query,但如果我不得不猜测,我会说:

$q = new WP_Query(array( 'jh-portfolio-category' => 'foobar',
                                     'post_type' => 'jh-portfolio' ));

答案 1 :(得分:0)

试试这个:

$args = array('posts_per_page'=>10,'post_type' => 'deposits','tax_query' => array(array('taxonomy' => 'deposit_types','field' => 'slug','terms' => '12-months')));

query_posts($args);

while (have_posts()) : the_post(); ...


我为一个项目测试了它,发现它正在工作。我的配置如下:

自定义帖子类型:存款(slug:deposit)
自定义分类:存款类型(slug:deposit_types)
自定义分类法类别:固定(slug:fixed)
自定义分类学子类别:12个月(slug:12个月)

答案 2 :(得分:0)

我不确定这是否有用,但你可以像这样创建你的SQL查询

select * from `wp_term_taxonomy` t1 ,`wp_terms` t2 where t1.`term_id` = t2.`term_id` and  t1.`taxonomy`='product_cat'

SELECT * FROM orderdb.wp_terms where term_id in (SELECT term_id FROM orderdb.wp_term_taxonomy where `taxonomy`='product_cat');
相关问题