解決させたいことは、複数タームのタクソノミー一覧ページで、ループで通常の投稿タイトルは正常に
取得可能ですが、カスタムフィールドのテキストが最初の1件目のみ取得され、2件目以降も1件目の値を引き継がれてしまいs、ループがされない状態です。
はじめは、the_filed('フィールド値')で取得しておりましたが、
以下の取得方法もあることを知り、試してみましたが、1件目すら取得できませんでした。
global $wp_query; $postID = $wp_query->post->ID; echo get_post_meta($postID, 'フィールド値', true);
ご教授いただけますでしょうか。
よろしくお願いいたします。
以下、タームのタクソノミー一覧のループになります。
<?php $args = array( 'parent' => 0, 'hierarchical' => 0, 'orderby' => 'term_order', // Category Order and Taxonomy Terms Order を使用 'order' => 'ASC' ); $taxonomy_name = 'shop_cat'; $taxonomys = get_terms($taxonomy_name,$args); if(!is_wp_error($taxonomys) && count($taxonomys)): foreach($taxonomys as $taxonomy): $url = get_term_link($taxonomy->slug, $taxonomy_name); $tax_posts = get_posts(array( 'post_type' => get_post_type(), 'posts_per_page' => -1, // 表示させたい記事数 'tax_query' => array( array( 'taxonomy'=>'shop_cat', 'terms'=>array( $taxonomy->slug ), 'field'=>'slug', 'include_children'=>true, 'operator'=>'IN' ), 'relation' => 'AND' ), /*'meta_query' => array( array( 'key'=>'shop-info-type', 'value'=>'Shop' ) )*/ )); if($tax_posts): ?> <ul id="area_<?php echo esc_html($taxonomy->slug); ?>"> <?php foreach($tax_posts as $tax_post): ?> <li> <h3 class="ttl"><?php echo get_the_title($tax_post->ID); ?></h3> <?php if( get_field('shop-info-type') == "代理店"): ?> <p class="shop-type">Distributor</p> <?php elseif( get_field('shop-info-type') == "ショップ"): ?> <p class="shop-type">Shop</p> <?php endif; ?> <table cellpadding="0" cellspacing="0"> <tr> <th>Address</th> <td> </td> </tr> <tr> <th>Contact</th> <td><?php the_field('shop-info-contact'); ?></td> </tr> </table> </li> <?php endforeach; ?> </ul> <?php endif; endforeach; endif; ?>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/06/30 12:06
2017/06/30 12:11
退会済みユーザー
2017/06/30 12:39
2017/06/30 12:48
退会済みユーザー
2017/07/01 09:19
退会済みユーザー
2017/07/01 11:06