我假设你正在使用一个类别来分开野营旅行&筹款人,但这种方法应该是关闭其他分离旅行/募捐人的方法。我还假设你想在循环之外或次循环中执行此操作。我没有测试过这个,但是这样的事情应该可以做到。
基本上这里就是打算做:
1)查询的筹款和露营两者按日期排序。
2)将两个查询合并在一起,这样募捐者就是第一位,露营旅行第二位。
3)遍历每个返回的帖子,并标记您喜欢的信息。
代码:
<?php //Enter your information for each variable:
$post_type = 'enter_your_custom_post_type_slug';
$fundraiserCatID = 'enter_your_fundaiser_category_id';
$campingCatID = 'enter_your_camping_category_id';
$acfDateFieldName = 'enter_your_date_acf_field_slug';
//Setup each Query args
$fundraiserAgrs = array('post_type' => $post_type, 'cat' => $fundraiserCatID, 'orderby' => 'meta_value', 'meta_key' => $acfDateFieldName, 'order' => 'ASC');
$campingAgrs = array('post_type' => $post_type, 'cat' => $fundraiserCatID, 'orderby' => 'meta_value', 'meta_key' => $acfDateFieldName, 'order' => 'ASC');
$fundraisers = get_posts($fundraiserArgs);
$campingTrips = get_posts($campingArgs);
$events = array_push($fundraisers, $campingTrips); //merge the two queries, with fundraisers first, then camping trips
if($events) : foreach($events as $event): //If we have $events, loop through each event
//Do what you will with the $event content ?>
<h1><?php echo $event->post_title; ?></h1>
<?php echo $event->post_content; ?>
<h6>Date: <?php the_field($acfDateFieldName, $event->ID); ?></h6>
<?php endforeach; endif; //End the loop and the conditional ?>