###前提・実現したいこと
WordPressである程度カスタマイズして、作業ができる程度の者です。
表題の通り、複数のカスタム投稿タイプを混在させた年別アーカイブページページを作りたいと考えています。
最初面倒だったので、'posts_per_page' => -1で全件表示しようとしていたのですが、
表示するのにも時間がかかってしまったので、改めて年別アーカイブページページを作りたいです。
カスタムフィールドを使っているので、カスタムフィールドのデートピッカーで指定している日付でソートできたら尚いいです。
- カスタム投稿タイプ「custom01」のアーカイブページを作成
- 「custom01」の年別アーカイブページでcustom01、custom02、custom03の内容を一括表示
これで、下記ソースで強制的に一覧表示はできたのですが、
custom01の投稿数が少ないため、年別アーカイブページを作成すると2017/2016/2014/2002/という形で、
歯抜けのページができてしまいます。
歯抜けができないようにするためにはどうしたらいいのか教えて欲しいです。
###該当のソースコード
<?php $args = array( 'post_type' => array( 'custom01','custom02','custom03'), 'paged' => $paged, 'meta_key' => 'first_date', 'orderby' => 'first_date', 'order' => 'ASC', 'post_status' => array('private','publish') ); ?> <?php query_posts( $args ); ?> <?php if ( have_posts() ): while ( have_posts() ): the_post(); get_template_part( 'content-custom01' ); endwhile; endif; wp_reset_query(); ?>
###補足情報
query_postsって・・・と指摘受けそうですが・・・
そこは、無視していただければ幸いです。
get_postsでの方法でも構いません。
###追加質問
回答してくださったmizさんの方法で大体の実現はできたのですが、最初に記述した
https://teratail.com/questions/67797
<?php $args = array( 'post_type' => array( 'custom01','custom02','custom03'), 'paged' => $paged, 'meta_key' => 'first_date', 'orderby' => 'first_date', 'order' => 'ASC', 'post_status' => array('private','publish') ); ?> <?php query_posts( $args ); ?> <?php if ( have_posts() ): while ( have_posts() ): the_post(); get_template_part( 'content-custom01' ); endwhile; endif; wp_reset_query(); ?>
では年別アーカイブに別の年まで入ってしまったため、
<?php if ( have_posts() ): while ( have_posts() ): the_post(); get_template_part( 'content-custom01' ); endwhile; endif; wp_reset_query(); ?>
とarchive.phpに記述しました。
実現はできましたが、これだと
最初に書いた条件の
<?php $args = array( 'meta_key' => 'first_date', 'orderby' => 'first_date', 'order' => 'ASC', 'post_status' => array('private','publish') ); ?> <?php query_posts( $args ); ?>
が実現されません。
一部カスタム投稿タイプは非公開になっている情報を取得したたいため、上記記述をしています。
コメントにも書いているのですが、
今回イベント情報ページで、
0. イベントが終わり次第、非公開になる
0. 非公開になったイベント情報をバイオグラフィに自動的に表示したい
という意図です。
当方でも調べてはいるものの、うまく実現できないため、再質問とさせてください。
よろしくお願いいたします
回答2件
あなたの回答
tips
プレビュー