いつもお世話になってます。
カスタム投稿ポストのターム(news_tag)に含まれる
全てのスラッグを対象に最新記事一覧を表示させたいのですが、
個別のスラッグやarrayでの複数スラッグは対応出来たのですが、
スラッグが全部で100以上あるので、タームを指定して
全てのスラッグを抽出できるような設定に変更したいです。
以下は現在設定中の表示用タグで、動作確認はOKです。
php
1<?php 2 $args = array( 3 'post_type' => 'news', 4 'post_parent' => 0, 5 'tax_query' => array( 6 array( 7 'taxonomy' => 'news_tag', 8 'field' => 'slug', 9 'terms' => 'ここを個別でなく、ターム(news_tag)全体を対象にしたい', 10 ), 11 ), 12 "posts_per_page" => 3 13 ); 14 $the_query = new WP_Query($args); if($the_query->have_posts()): 15 ?> 16 <?php while ($the_query->have_posts()): $the_query->the_post(); ?>
また、function.phpに記載している内容は
以下になります。
php
1/*news*/ 2add_action( 'init', 'news' ); 3function news() { 4 global $current_user; 5get_currentuserinfo(); 6if ($current_user->ID == "1" ) { 7 $flag = true; 8}else{ 9 $flag = false; 10} 11 register_post_type( 'news', 12 array( 13 'labels' => array( 14 'name' => __( 'ブログ' ), 15 'singular_name' => __( 'news' ) 16 ), 17 'public' => true, 18 'show_ui' => $flag, 19 'supports' => array( 'title', 'editor', 'comments', 'thumbnail' ), 20 'menu_position' =>3, 21 'has_archive' => true 22 ) 23 ); 24 25//カスタムタクソノミー、タグタイプ 26 register_taxonomy( 27 'news_tag', 28 'news', 29 array( 30 'hierarchical' => false, 31 'update_count_callback' => '_update_post_term_count', 32 'label' => 'ブログのタグ', 33 'singular_label' => 'ブログのタグ', 34 'public' => true, 35 'show_ui' => true 36 ) 37 ); 38 39} 40 41function get_current_term(){ 42 43 $id; 44 $tax_slug; 45 46 if(is_category()){ 47 $tax_slug = "category"; 48 $id = get_query_var('cat'); 49 }else if(is_tag()){ 50 $tax_slug = "post_tag"; 51 $id = get_query_var('tag_id'); 52 }else if(is_tax()){ 53 $tax_slug = get_query_var('taxonomy'); 54 $term_slug = get_query_var('term'); 55 $term = get_term_by("slug",$term_slug,$tax_slug); 56 $id = $term->term_id; 57 } 58 59 return get_term($id,$tax_slug); 60}
ぜひお力添えを頂けますと幸いです。
回答1件
あなたの回答
tips
プレビュー