カスタムフィールドでフィルタした、カテゴリ別記事一覧
-
カスタムフィールドの値で以下のようにフィルタをしたのですが、category.phpに記載したときはカテ別に記事が表示されるものの、single.phpに同記載を表示すると全カテゴリからの3記事表示となりました。
その記事が属している親カテゴリ(子カテ、孫カテ)のカスタムフィールドでフィルタ下記事を表示させるには以下をどのように編集すれば宜しいでしょうか?-
<?php
$cat = get_query_var(‘cat’);
$featured = get_posts( array (
‘meta_query’ => array (array(
‘key’ => ‘【カスタムフィールドの設定】’,
‘value’ => ‘【カスタムフィールドの値】’
)),
‘posts_per_page’ => 3,
‘orderby’ => ‘modified’,
‘category’ =>$cat
));
foreach($featured as $post):
setup_postdata($post);
?>
<li class=”clearfix”>” name=”sideRecommendImg_<?php the_title(); ?>”><?php the_post_thumbnail(‘thumbnail’); ?>
<div>
<h2>” name=”sideRecommendTxt_<?php the_title(); ?>”><?php the_title(); ?></h2>
<p class=”sub”> <?php
echo “<span class=\”cat$top_cat_id cat\”>”.$top_cat->name.”</span>”;
?><span class=”views”><?php if(function_exists(‘the_views’)) {the_views();} ?></span></p>
</div><?php endforeach; wp_reset_postdata(); ?>
1件の返信を表示中 - 1 - 1件目 (全1件中)
1件の返信を表示中 - 1 - 1件目 (全1件中)
- トピック「カスタムフィールドでフィルタした、カテゴリ別記事一覧」には新たに返信することはできません。