![]() |
I'm having issues with pagination. I'm using it on a wp_query.
The pagination outputs, and the links work, but the loop stays on the same page, posts never change.
Here is my code...
(i'm setting posts per page as 1 as I only have 3 posts)
If I dump $paged, what ever page link I visit always returns 1. If change $paged to 2 or 3 it the loop outputs the correct page. I'm guessing https://www.mysite.com/suppliers - $paged returns 1 https://www.mysite.com/suppliers/page/2 - $paged returns 1 https://www.mysite.com/suppliers/page/3 - $paged returns 1 If I dump `get_query_var( 'paged')` it just returns zero on any of those page links above. What am I missing to get this working. I do not want to use URL vars with `?page=3`, i want clean `/page/3` etc. I this possible? Solution - 1please read this https://www.webdesignvista.com/how-to-make-pagination-work-with-wp_query-custom-loop-in-wordpress/ and this https://njengah.com/custom-query-pagination-in-wordpress/ Solution - 2Try removing the ], 'posts_per_page' => 1 ]; or changing it to -1 Solution - 3I think the problem is here: when you are in the loop you have to access the post from the global $post, not from the query. but you can just use the wp functions to retrieve post details, which will automatically pull from the currently looped post when you're inside the loop and you don't specifify a post_id as parameter of the function. so for instance you can just do: Solution - 4Try changing to: 'paged' => get_query_var( 'page' ) |
Wordpress |
Type: | Code Example |
Category: | Coding |
Sub Category: | Code Example |
Uploaded by: | Admin |
Views: | 43 |