Home>

I want to implement a page feed by wp_pagenavi after displaying a post on a custom post type "A" archive page (including yearly) as shown in the title.
Page feed moved on a fixed page with the following code,
In the archive page for custom posts, the page feed does not work well and becomes 404.

Applicable source code

archive-custom_post_a.php

<? php
  $paged = get_query_var ('paged')? get_query_var ('paged'): 1;
  if (is_year ()) {
    $args = array (
      'post_type' =>array ('custom_post_a', 'post'),
      'posts_per_page' =>9,
      'paged' =>$paged,
      'meta_key' =>'show_archive',
      'meta_value' =>'show',
      'meta_compare' =>'LIKE',
      'year' =>$year,
    );
  } else {
    $args = array (
      'post_type' =>array ('custom_post_a', 'post'),
      'posts_per_page' =>9,
      'paged' =>$paged,
      'meta_key' =>'show_archive',
      'meta_value' =>'show',
      'meta_compare' =>'LIKE',
    );
  }
?>
<? php $myquery = new WP_Query ($args);?>
<? php if ($myquery->have_posts ()):?>
  <? php while ($myquery->have_posts ()): $myquery->the_post ();?>
// loop contents
  <? php endwhile;?>
<? php endif;?>
<? php
  wp_pagenavi (array ('query' =>$myquery));
  wp_reset_query ();
?>
Supplement

I'm planning to send a page by nine.
Page feed works when the number of posts of custom post type "A" exceeds 11,
If it is less, the second page will be 404.

The part that does not move if it is an archive, moves if the number exceeds 11 ... There was nothing I could understand even after searching.
If i know someone, can you professor?

Append

Custom Post Type UI is used to add custom post types.

  • Answer # 1

    It has been resolved, but rewriting the query withpre_get_postsis lighter and less likely to cause problems than withnew WP_Query.

    【【wordpress】 Would you like to use pre_get_posts? ]
    https://qiita.com/_ruka_/items/e14280d34eddf49efad1#pre_get_posts suggestions

    [Control main query with pre_get_posts | Tips Note by TAM]

    [Use [Wordpress] pre_get_posts! pre_get_postsHow to use | EMiAC-Works】
    https://emiac-works.com/coding/pre-get-posts-code-snipet/

  • Answer # 2

    Self-solved above.
    "Maximum number of posts to be displayed on one page" on the management screen is 10 cases,
    It seemed to be because the number of posts_per_page was exceeded.