0

サブページを許可するイベントのカスタム ページ タイプがあり、サブ ページの日付順にイベント ページを並べ替えたいと考えています。

だから私の構造は次のようなものです:

キャンプ旅行:

  • テキサスキャンプ旅行 (日付のカスタムフィールド: 2/12/2014)
  • ユタ州のキャンプ旅行 (日付のカスタム フィールド: 2014 年 3 月 10 日)

募金活動:

  • ベイクセール (日付のカスタムフィールド: 1/30/2014)
  • サイレント オークション (日付のカスタム フィールド: 2014 年 5 月 1 日)

ページをクエリするときは、募金活動、キャンプ旅行の順に返してほしいと思います。

4

1 に答える 1

0

カテゴリを使用してキャンプ旅行と募金活動を分離していると思いますが、この方法は、旅行/募金活動を分離する他の方法に近いはずです。また、これをループの外で、または 2 次ループとして実行することも想定しています。私はこれをテストしていませんが、このようなものがうまくいくはずです。

基本的にここに何をしようとしていたかです:

1) 募金活動とキャンプ旅行の両方を日付順にクエリします。

2) 2 つのクエリをマージして、募金活動が最初で、キャンプ旅行が 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 ?>
于 2014-02-09T00:34:23.123 に答える