お世話になります。
wordpressのCPT UIとACFで絞り込み検索を実装したいと思っています。
カスタム投稿 Post
カスタムタクソノミー Category(親子関係があります)
以下のようなコードで投稿を取得したいのですが、カスタムタクソノミーの親で絞り込みする事が出来ずに困っています。
表現が難しいのですが、投稿を取得する際に、カスタムタクソノミーの親IDで投稿を取得したいといった内容になります。
PHP
1 // 親を持つ場合 2 if ($category->parent != 0) { 3 $args = array( 4 'post_type' => 'post', 5 'post_status' => 'publish', 6 'posts_per_page' => -1, 7 'meta_key' => 'category', 8 'meta_value' => $category->term_id 9 ); 10 // 親をもたない場合 11 } else { 12 $args = array( 13 'post_type' => 'post', 14 'post_status' => 'publish', 15 'posts_per_page' => -1, 16 'parent' => $category->term_id 17 ); 18 } 19 $query = new WP_Query($args);
具体的には、"子"カスタムタクソノミーの親IDで絞り込みをしたいといったところです。
うまい方法が見当たらず質問させていただきました。
追記
PHP
1 if ($cat->parent != 0) { 2 $args = array( 3 'post_type' => 'post', 4 'post_status' => 'publish', 5 'posts_per_page' => -1, 6 'meta_key' => 'maker', 7 'meta_value' => $cat->term_id 8 ); 9 } else { 10 $args = array( 11 'post_type' => 'post', 12 'post_status' => 'publish', 13 'posts_per_page' => -1, 14 'tax_query' => array ( 15 array ( 16 'taxonomy' => 'category', 17 'field' => 'parent', 18 'terms' => array ($cat->term_id), 19 'include_children'=>true, 20 'operator' => 'AND' 21 ) 22 ), 23 // 'parent' => $cat->term_id 24 ); 25 } 26 $query = new WP_Query($args);

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/17 20:11 編集
2018/02/18 02:06
2018/02/18 08:32
2018/02/18 08:45
2018/02/18 08:56
2018/02/18 09:05
2018/02/18 10:29
2018/02/18 10:45
2018/02/18 13:30