我假設你正在使用一個類別來分開野營旅行&籌款人,但這種方法應該是關閉其他分離旅行/募捐人的方法。我還假設你想在循環之外或次循環中執行此操作。我沒有測試過這個,但是這樣的事情應該可以做到。
基本上這裏就是打算做:
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 ?>