質問: get_posts( array( 'showposts' => -1, 'post_type' => 'fabric_building', 'tax_query' => array( array( 'taxonomy' => 'fabric_building_types', 'field' => $cat->cat_id, 'terms' => $cat->name, ) ) ) ); print_r( $posts_array ); } 誰かが私を手伝ってくれますか。
回答: 可能であれば、分類法にget_terms()を使うべきです。<?php /* add your taxonomy. */ $taxonomies = array( 'fabric_building_types', ); $args = array( 'orderby' => 'name', 'order' => 'asc', 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); $terms = get_terms( $taxonomies, $args ); foreach ( $terms as $term ) { // here's my code for getting the posts for custom post type $posts_array = get_posts( array( 'showposts' => -1, 'post_type' => 'fabric_building', 'tax_query' => array( array( 'taxonomy' => 'fabric_building_types', 'field' => term_id, 'terms' => $term->name, ) ) ) ); print_r( $posts_array ); } ?> codexへのリンク : http://codex.wordpress.org/function_reference/get_terms