I am able to retrieve all the posts from a custom category with this call to WP_Query
$q = new WP_Query(array( 'taxonomy' => 'jh-portfolio-category',
'term' => 0, 'post_type' => 'jh-portfolio' ));
However, let say within the jh-portfolio-category taxonomy I have defined some sub-categories, how do I specify I wish to have posts from a specific sub-category? Changing the 'term' property to the term_id as pres开发者_Python百科ented in wp_term_taxonomy doesn't seem to work. All the posts within that taxonomy is still being listed.
I'm not sure if this is helpful to you. I had a similar problem where I was trying to get_posts that were of a custom post_type and taxonomy.
The name of your post_type is jh-portfolio
. Your taxonomy is called jh-portfolio-category
. You didnt specify the name of your term in your post, so lets call it foobar
. Your get_posts or query_posts function would look like this:
get_posts("post_type=jh-portfolio&jh-portfolio-category=foobar");
query_posts("post_type=jh-portfolio&jh-portfolio-category=foobar");
I'm not sure how this would translate to WP_Query, but if I had to guess, I would say:
$q = new WP_Query(array( 'jh-portfolio-category' => 'foobar',
'post_type' => 'jh-portfolio' ));
Try this:
$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();
...
I tested it for a project and found it is working. My configuration is as below:
Custom Post Type: Deposits (slug: deposits)
Custom Taxonomy: Deposit Types (slug: deposit_types)
Custom Taxonomy Category: Fixed (slug: fixed)
Custom Taxonomy sub-Category: 12 Months (slug: 12-months)
I am not sure this is helpful or not but you can create your sql query like this
select * from `wp_term_taxonomy` t1 ,`wp_terms` t2 where t1.`term_id` = t2.`term_id` and t1.`taxonomy`='product_cat'
or
SELECT * FROM orderdb.wp_terms where term_id in (SELECT term_id FROM orderdb.wp_term_taxonomy where `taxonomy`='product_cat');
精彩评论