1
1ページのために、特定のカテゴリからのアイテムのリストのみを取得するコードを変更する必要があります。そうです:カテゴリーフードが15の商品を選択してください。ワードプレスで配列の特定の投稿を取得
私は別のものを試しましたが、私はPHPでそれほど良くありません。だから、コードを変更するのを手伝ってください。ここにリストが公開される部分があります。
<div class="col-md-6">
<div class="box_style_2" id="main_menu">
<h2 class="inner">Menu</h2>
<?php
$terms = get_terms('foodcat', array(
'include' => $category_food,
));
?>
<?php
$i = 1;
foreach($terms as $term){ ?>
<h3 <?php if($i=1){?>class="nomargin_top"<?php }else{}?> id="<?php echo esc_attr($term->slug);?>"><?php echo esc_attr($term->slug);?></h3>
<p><?php echo esc_attr($term->description);?></p>
<table class="table table-striped cart-list">
<thead>
<tr>
<th>
<?php echo esc_html__('Item', 'quickfood');?>
</th>
<th>
<?php echo esc_html__('Price', 'quickfood');?>
</th>
<th>
<?php echo esc_html__('Order', 'quickfood');?>
</th>
</tr>
</thead>
<tbody>
<?php
$food_arr = new WP_Query(
array(
'post_type' => 'food',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'foodcat',
'field' => 'id',
'terms' => $term->term_id,
)
)
)
);
$ii = 1;
if($food_arr->have_posts()) : while($food_arr->have_posts()) : $food_arr->the_post();
$textmoney = get_post_meta(get_the_id(), '_cmb2_textmoney', true);
?>
<tr id="detail-<?php the_id();?>">
<input type="hidden" value="<?php the_id();?>">
<td>
<h5><?php echo esc_attr($ii);?>.<span class="name-<?php the_id();?> item_name"><?php the_title();?></span>
<input type="hidden" id="name-<?php the_id();?>" value="<?php the_title();?>">
</h5>
<p>
<?php the_content();?>
</p>
</td>
<td>
<strong><?php if(isset($currency_menu) && !empty($currency_menu)){ echo esc_attr($currency_menu);}else{}?><span class="price-<?php the_id();?> price"> <?php echo esc_attr($textmoney);?></span></strong>
<input type="hidden" id="price-<?php the_id();?>" value="<?php echo esc_attr($textmoney);?>">
</td>
<td class="options">
<a href="#0"><i class="icon_plus_alt2 add-to-cart-button" id="<?php the_id();?>"></i></a>
</td>
</tr>
<?php $ii++; endwhile;endif;?>
</tbody>
</table>
<hr>
<?php } ?>
</div>
</div>
get_posts()を使用してカテゴリに制限する必要がありますか? https://codex.wordpress.org/Template_Tags/get_posts – elicohenator