1

私はWordpressを使用していて、親子関係のあるカテゴリを持っています。 高度なカスタムフィールドを使用してカスタムフィールドをカテゴリに追加しました。子カテゴリをループし、archive.phpのカスタムフィールドを出力

archive.phpページで、各子カテゴリのタイトルとカスタムフィールドのフォームを子カテゴリとして表示したいと思います。私は現在、以下のように子カテゴリのタイトルを出力しています -

<?php $this_cat = get_query_var('cat'); 
wp_list_categories('child_of=' . $this_cat . '&title_li=&show_option_none=&depth=1&hide_title_if_empty=true');?> 

いずれかの子カテゴリおよび出力フィールド通じにも能力出力カスタムフィールド、または道に実際にループを含めるする方法はありますか?

答えて

0

あなたは、子カテゴリを取得するために税のクエリを使用して、WPクエリとそれらをループ、このような何か必要があります。

<?php 

    $this_cat = get_query_var('cat'); 

$args = array(
    'tax_query' => [ 
     [ 
      'taxonomy' => 'category', 
      'terms' => $this_cat, 
     ], 
    ], 
); 

$query = new WP_Query($args); 
if ($query->have_posts()) : ?> 
    <?php while ($query->have_posts()) : $query->the_post(); 

    //get your custom field 
    $yourField = get_field('field_name'); ?> 

    <div> 
     <?php echo $yourField ?> 
    </div> 

    <?php endwhile; ?> 
<?php endif; ?> 
<?php wp_reset_postdata(); ?> 
関連する問題