Home › Forums › Front-end Issues › Pagination on custom WP_query
Hello
I asked the forum for help yesterday. That was nice to have a response 🙂
Read this one : https://support.advancedcustomfields.com/forums/topic/wp_query-checkbox-array-string-error/
Today I have another problem on this WP query with pagination
I had this code
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 2,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => $qobjet->taxonomy,
'field' => 'id',
'terms' => $qobjet->term_id,
),
),
'meta_query' => $meta_query
);
$query = new WP_Query($args);
and this code for pagination
wp_pagenavi( array( 'query' => $query ) );
This URL is ok
http://localhost/ajr2/cadeaux/cadeaux-anniversaire-femme/?genre=femme&minprice=&maxprice=&passion%5B%5D=animaux
This one (page 2) give me a 404
http://localhost/ajr2/cadeaux/cadeaux-anniversaire-femme/page/2/?genre=femme&minprice&maxprice&passion%5B0%5D=animaux
How to fix that ?
What happens if you just try to load http://localhost/ajr2/cadeaux/cadeaux-anniversaire-femme/page/2/
I don’t really understand the URL, but the page in question has to support pages. What I mean by that is that this url http://localhost/ajr2/cadeaux/cadeaux-anniversaire-femme/ must be a archive page of some kind to begin with.
Hello
This one is a 404 too
http://localhost/ajr2/cadeaux/cadeaux-anniversaire-femme/page/2/
It’s a custom taxonomy that I made in My function.php file
function cadeaux() {
register_taxonomy('cadeaux','post', [
'labels' => [
'name' => 'Cadeaux'
],
'show_in_rest' => true,
'hierarchical' => true,
'show_in_quick_edit' => true,
'show_admin_column' => true,
]);
}
add_action('init','cadeaux');
Do u need more informations ?
The only thing that tells me is that your term “cadeaux-anniversaire-femme” does not have enough posts in it to have more than one page.
This would be determined by the number of posts per page set for the blog or the default number and would not be determined by the number is your custom query.
Your code should probably not be done as a custom query but it should be done in a pre_get_posts action to alter the main query. https://developer.wordpress.org/reference/hooks/pre_get_posts/
The number of posts per page in the main query determines whether or not there are multiple pages and will not be affected by your custom query.
Really, you should not be doing a custom query on a page that is already doing the same query. You should be altering the main query based on your inputs.
I m so sorr thy.. that’s right, I done a mistake in default number setting… Now that’s work !
That query is just a test on a custom toxonomy, but I ll made it only on a big cat.
This site is a bit complexe with almost 80 categories and 40 toxonomies more 30 customs fields… So query something is a bit hard for me 😀
Thanks a lot for your nice support !
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.