前回の質問に回答してくださった方ありがとうございました。おかげで、解決することができたのですが色々不都合が出てきたので新たな方法を探っていますが、どうしても行き詰まってしまいました・・・・。
--------------以下が内容です-------------------
ワードプレスのアーカイブページでカテゴリに属するコメントを表示する為に、
$i = 0; global $wpdb; global $data; $query = " SELECT comment.comment_content, comment.comment_date, post.ID, post.post_title, post.post_name, meta.meta_value, count.count FROM ( SELECT cur.comment_ID, cur.comment_post_ID, cur.comment_content, cur.comment_date FROM wp_comments cur LEFT JOIN wp_comments nxt ON cur.comment_post_id = nxt.comment_post_ID AND cur.comment_date < nxt.comment_date WHERE nxt.comment_post_ID IS NULL AND cur.comment_approved = 1 ORDER BY cur.comment_date DESC ) comment, ( SELECT ID, post_title, post_name FROM wp_posts, wp_term_relationships term WHERE wp_posts.ID = term.object_id AND wp_posts.post_status = 'publish' AND term.term_taxonomy_id = 36 ) post, ( SELECT comment_ID, meta_value FROM wp_commentmeta WHERE meta_value is not null ) meta, ( SELECT count(comment_ID) as count, comment_post_ID FROM wp_comments WHERE comment_approved = 1 GROUP BY comment_post_ID ) count WHERE comment.comment_ID = meta.comment_ID AND comment.comment_post_ID = post.ID AND comment.comment_post_ID = count.comment_post_ID AND post.post_title IS NOT NULL ORDER BY comment.comment_date DESC LIMIT 30; "; $e = single_cat_title('',false); $data = $wpdb->get_results($query); foreach ($data as $value): $r = get_the_terms($value -> ID,'category'); $q = array_column ($r, 'name'); if ( !in_array($e,$q)){ continue; } else{表示したい内容} $i++; endforeach; wp_reset_postdata(); endif;
としてみたのですが、どうしてもうまく行きません
一旦出力してみて確認してみた所、
$e = single_cat_title('',false);
は正しく取得できていて、
$r = get_the_terms($value -> ID,'category');
の多次元配列までは取得できているようなのですが、
$q = array_column ($r, 'name');
が
Array ( )になってしまいます。
かなり初心者の為に解決方法を色々手探りで調べてみてここまでは特定できましたが、間違いがわからないので、どなたか詳しい方お願い致します。
回答1件
あなたの回答
tips
プレビュー