我在一个页面模板中使用以下代码20次,以查询每个部分的特定数据。所有页面数据都来自同一个帖子类型,只是我需要将其除以一个特定的自定义字段值,然后按另一个特定的自定义字段值排序。是否有一种方法可以只运行一次WP\\U查询,然后根据一个自定义字段值将数据过滤到组中,然后按另一个字段值排序??
<div id="listings">
<?php
$args = array(
\'post_type\' => \'listing\',
\'post_status\' => \'publish\',
\'posts_per_page\' => \'96\',
\'meta_key\' => \'price_value\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'category_value\',
\'value\' => \'category 1\',
),
array(
\'key\' => \'sold_value\',
\'value\' => \'No\'
)
)
);
$custom = new WP_Query( $args ); ?>
<h3 class="bar">Category 1 (<?php echo $custom -> found_posts; ?>)</h3>
<?php $margincounter = 1; ?>
<?php if ($custom->have_posts()) : while ($custom->have_posts()) : $custom->the_post(); ?>
<?php include get_template_directory() . \'/includes/listings_grid.php\'; ?>
<?php endwhile; else: ?>
<?php endif; wp_reset_query(); ?>
</div>