お世話になります。
2つのカスタム投稿のタイトル一覧記事を作成したいと思っています。
post_type:「news」「flyer」 があり、
「news」は、ターム「event」のみを出力し、「flyer」 に関してはターム指定がなくすべての記事を表示したいです。
下記のようにすると、「flyer」 もターム指定してしまい困っております。
宜しくお願いいたします。
php
1 2<?php 3 $toplist = array( 4 'post_type' => array('news','flyer'), 5 'tax_query' => array( 6 'relation' => 'OR', 7 array( 8 'taxonomy' => 'news_cat', /* 指定したい投稿タイプが持つカスタム分類を指定 */ 9 'field' => 'slug', 10 'terms' => 'event', /* 指定したカスタム分類が持つタームのスラッグを指定 */ 11 ), 12 array( 13 'taxonomy' => 'flyer_cat', /* 指定したい投稿タイプが持つカスタム分類を指定 */ 14 'field' => 'slug', 15 'terms' => 'gas', /* 指定したカスタム分類が持つタームのスラッグを指定 */ 16 ), 17 ), 18 'showposts' => 10, 19 'order' => 'DESC', 20 'orderby' => 'date', 21 'ignore_sticky_posts' => 1, 22 ); 23 ?> 24 25 <?php query_posts($toplist); ?> 26 27 28 <?php if (have_posts()): ?> 29 <ul> 30 31 <?php while(have_posts()):the_post(); ?> 32 <?php $post_type = esc_html(get_post_type_object(get_post_type())->name); ?> 33 <?php if($post_type=='news'): ?> 34 <li><span><?php the_time('Y.m.d'); ?></span><span><a href="<?php bloginfo('url'); ?>/news/#<?php the_ID(); ?>"><?php echo mb_substr($post->post_title, 0, 30).'…'; ?></a></span></li> 35 36 <?php else : ?> 37 <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 38 <?php endif; ?> 39 <?php endwhile; ?> 40 41 </ul> 42 <?php else : ?> 43 <p>ただいま準備中です。しばらくお待ちください。</p> 44 <?php endif; ?> 45 46 <?php wp_reset_postdata(); wp_reset_query(); ?> 47 48 49
![guest](/https/teratail.com/img/icon/icnUserSample.jpg)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/10 06:53