2010-05-13 53 views
0

我能够使用该调用检索自定义类别的所有职位,以WP_Query的WordPress:Retriving特定的自定义类别的职位在自定义分类

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

然而,让内部的JH-portfolio-说类别分类我已经定义了一些子类别,我如何指定我希望从一个特定的子类别中发布帖子?如wp_term_taxonomy中所示,将“term”属性更改为term_id似乎不起作用。该分类中的所有帖子仍在列表中。

回答

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')); 
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(); ...


我测试了它的项目,发现它工作。我的配置是如下:

自定义文章类型:存款(毛坯:存款)
自定义分类:矿床类型(毛坯:deposit_types)
自定义分类类别:固定(毛坯:固定)
自定义分类子 - 类别:12个月(毛坯:12个月)

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'); 
相关问题