• アーカイブページで先頭にSeamless Sticky Custom Post Typesを使用して固定表示し、その下にその他の投稿を表示させるべく、2つのクエリを作成し結合しております。
    しかし、その場合正常にページネーションが動作しません。

    ページネーションで使用しているプラグインはWP-Page-Naviになります。
    また1ページに最大12件の投稿を行いたいです。(管理画面上での設定はすでにしてあります)

    こちらのリンクを参考に制作したのですが、最後がarray型で返ってくることからどのように記述していいのかわからないためお分かりになる方ご教授いただけますと幸いです。
    https://www.fourier.jp/blog/display-custom-posts-fixed-at-the-top

     <div class ="gallery-wrapper">
    <?php
    $term_object = get_queried_object(); // タームオブジェクトを取得
    $term_slug = $term_object->slug; // タームスラッグ
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $sticky_args = [
    'posts_per_page' => -1,
    'order' => 'DESC',
    'post_status' => 'publish',
    'post_type' => 'gallery',
    'paged' => $paged,
    'tax_query' => array(
    array(
    'taxonomy' => 'gallery-cat',
    'field' => 'slug',
    'terms' => $term_slug,
    ),
    ),
    'post__in' => get_option('sticky_posts')
    ];

    $args = [
    'posts_per_page' => -1,
    'order' => 'DESC',
    'post_status' => 'publish',
    'post_type' => 'gallery',
    'paged' => $paged,
    'tax_query' => array(
    array(
    'taxonomy' => 'gallery-cat',
    'field' => 'slug',
    'terms' => $term_slug,
    ),
    ),
    'post__not_in' => get_option('sticky_posts')
    ];

    $sticky_query = new WP_Query($sticky_args); // 固定表示の記事を取得
    $the_query = new WP_Query($args); // 固定表示以外の記事を取得

    $new_query = new WP_Query();
    $new_query->posts = array_merge( $sticky_query->posts, $the_query->posts );
    $display_posts = array_slice($new_query, (max(1, get_query_var('paged')) - 1) * 12, 12); // 1ページに10記事ごと取得する
    ?>

    <?php
    if($new_query -> have_posts()):
    while ( $new_query -> have_posts() ) : $new_query -> the_post();
    ?>

    //ここにループ投稿

    <?php endwhile; ?>
    <?php endif; ?>

    </div>

    <div class ="page-nation">
    <?php
    if(function_exists('wp_pagenavi')):
    wp_pagenavi(array('query'=>$new_query));
    endif;
    ?>
    </div>
3件の返信を表示中 - 1 - 3件目 (全3件中)
  • モデレーター 瀬戸内ことり (Setouchi Kotori)

    (@setouchikotori)

    ご質問への回答ではないのですが。

    Seamless Sticky Custom Post Types は最終更新日が10年前です。PHP や WordPress 等々のバージョンに対応していない可能性を懸念されたほうがよいかもしれません。

    (開発がストップしている場合、セキュリティリスクが発生した場合にも開発者による対応がなされません)

    トピック投稿者 azejun0127

    (@azejun0127)

    ご助言いただきありがとうございます!
    もともとタクソノミーで優先したい投稿を分別しおり、優先的に表示するタームのみのループとそれ以外のものを表示するループを作成して記述していたのですが、その場合でも2つのクエリを複合する必要があり、どのように記述をしていいのかわからないためこちらご教授いただけますと幸いです。

    モデレーター 瀬戸内ことり (Setouchi Kotori)

    (@setouchikotori)

    すみません、そちらについては詳しくないため、他の有識者の回答をお待ちになってみてください。

3件の返信を表示中 - 1 - 3件目 (全3件中)

トピック「2つのクエリを結合した際のページネーション」には新たに返信することはできません。