A list of custom posts (events) is output to the top in Wordpress.
The source is written as follows.
<? php $paged = get_query_var ('paged')? get_query_var ('paged'): 1; $args = array ( 'paged' =>$paged, 'post_type' =>'events', 'posts_per_page' =>4, ); $toppage_query = new WP_Query ($args); ?> <? php if ($toppage_query->have_posts ()):?> <? php while ($toppage_query->have_posts ()): $toppage_query->the_post ();?> ,<h3><a href = "<? Php the_permalink ();?>"><? Php the_title ();?></a></h3> <? php endwhile;wp_reset_postdata ();?> <? php else:?> <? php endif;?> <? php if (function_exists ('wp_pagenavi')) wp_pagenavi (array ('query' =>$toppage_query));?>
The pagination is displayed using the plug-in "wp_pagenavi".
Pagination is displayed normally and matches the number of submissions, but if you click 2, 3, 4 or next, it will be 404. (URL is/page/2 /)
I saw a variety of online literature,
(1) Return the Palmer link to the default (/? Paged = 2).
②Posts_per_page'=>Align the number 4 with the number of "maximum number of posts to be displayed on one page".
(3) In the case of wp_pagenavi, instead of aligning as in (2), reduce the number of "maximum number of posts displayed per page".
and all three, but no matter what I do, it remains 404 ...
How can I solve this phenomenon?
Could someone please professor?
Answer # 1
It is recommended to rewrite with pre_get_posts. WP_Query can be executed or paged on the template, but it is a waste of resources because the main query is executed once when the template is called. pre_get_posts is a method to rewrite before executing the main query.
【【wordpress】 Would you like to use pre_get_posts? ]
[Control main query with pre_get_posts ｜ Tips Note by TAM]
- php - i want to introduce the pagination function to the list of custom posted pages
- php - i want to add pagination to the list of custom posts
- php - [wordpress] pagination of custom taxonomy term archive page becomes 404
- i want to sort while acquiring terms in the custom field (php) of wp
- php: i want to echo specific lines after using fopen, fgets and while statements
- php user display after login
- php - i would like to move the image of the custom field of movable type to the eye catch of wordpress
- php - can't display custom post type page only for specific theme
- php - i want to change the query after a certain number of times with a wordpress subloop
- php - i want to load css individually using a custom field on the fixed page of wordpress
- php - i want to get the total of custom fields displayed in search results in wordpress
- php - after registering as a member, how to assign a membership number at the recipient
- php - after conditional branching, i want to hide posts that meet the conditions from the archive
- php - i want to specify the url of the thanks page of contactform7 in a custom field
- about syntax error after php version upgrade
- php - i want to introduce a pagination function to a site created with wordpress
- php - i want to change the order by the custom field value (date)
- php - [wordpress] pagination is not displayed
- php - if you do a narrowed search on the custom post page, you will jump to the post page
- php - fadetoggle does not work with custom js on wordpress and mobile menu does not close
- php - i want to display a fixed page on the front page of wordpress
- php - i want to include a custom field in the search result with a check box in wordpress
- php - [wordpress] to output all posted article titles in the list
- php - wordpress: output 5 each for each category, but want to exclude the category with id○○
- [wordpress] even if you apply php code, you want to make it responsive like the original html
- php - why doesn't lock tables work unless i write "table prefix (wp_)" in wordpress?
- php - why is the link on the lower page broken when the wordpress site is moved to another server?
- php - i want to rewrite the url discharged by wp_get_archives
- php - [wordpress] acquisition of whether there is a comment field (status?)
- php - html code of sidebar is not reflected when creating wordpress theme