나는 캠핑 여행을 분리하기 위해 카테고리를 사용하고 있다고 가정합니다. & 모금 행사이지만이 방법은 출장/기금 모금 행사를 분리하는 다른 방법과 비슷해야합니다. 또한 루프 밖에서 또는 보조 루프로이 작업을 수행하려고한다고 가정합니다. 나는 이것을 테스트하지는 않았지만 이것과 같은 것이 트릭을해야한다. 기본적으로 여기
는 할 거라고 것입니다 :
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 ?>