BBpressで作った掲示板「topic」の人気記事出力にあたって、下記$value2
が1つの値しか出力してくれません。
実際には「rabbit」と「lion」が保存されているのに、「rabbit」しか出力しないという感じです。
コメントで「//ここから怪しい」を書いておいたので、ちょっと見て頂けませんでしょうか?
###問題のコード
php
1<?php 2function get_the_term_list_nolink( $id = 0, $taxonomy, $before = '', $sep = '', $after = '' ) { 3 $terms = get_the_terms( $id, $taxonomy ); 4 if ( is_wp_error( $terms ) ) 5 return $terms; 6 if ( empty( $terms ) ) 7 return false; 8 foreach ( $terms as $term ) { 9 $term_names[] = $term->name ; 10 } 11 return $before . join( $sep, $term_names ) . $after; 12} 13 14 15function my_custom_single_popular_post( $post_html, $p, $instance ){ 16 17//ここから怪しい 18$tags = ['rabbit','lion','beaver','horse']; 19foreach($tags as $tag){ 20 $value1 = get_post_meta($p->id, $tag, false); 21 foreach ($value1 as $value2 ) { 22 } 23} 24//ここまで怪しい 25 26$custom_id = $p->id; 27$output = ' 28<div id="bbp-topic-popular-<?php bbp_topic_id(); ?>" <?php bbp_topic_class(); ?>> 29 <a href="' . get_the_permalink($p->id) . '"> 30 <div class="topic-tag"> 31 <ul><li>'.$value2.'</li></ul> 32 </div> 33</div> 34'; 35return $output; 36} 37add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 ); 38?> 39 40<div class="popular-topics"> 41<?php 42if (function_exists('wpp_get_mostpopular')){ 43$arg = array ( 44'range' => 'monthly', 45'order_by' => 'views', 46'stats_views' => '0', 47'post_type' => 'topic', 48'title_length' => '20', 49'limit' => 15, 50'wpp_start' => '<ul>', 51'wpp_end' => '</ul>', 52); 53wpp_get_mostpopular($arg); 54} 55?> 56</div>
###出力結果
このコードでの出力は「rabbit」だけです。
html
1<ul> 2 <li>rabbit</li> 3</ul> 4
実際には「「lion」の値もあるので、このように出力して欲しいです。
html
1<ul> 2 <li>rabbit</li> 3 <li>lion</li> 4</ul> 5
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/31 02:15
2018/07/31 03:37
退会済みユーザー
2018/07/31 11:04
退会済みユーザー
2018/07/31 12:25 編集