Pagenavi(); in custom wp query

I set up a page with a custom wp_query to call a category of a custom post type.

The query works fine, and only shows the number of post in the posts_per_page argument, but when I add pagenavi(), the pagination function doesn’t work at all. Am I doing something wrong?

Here is my query:

	// WP_Query arguments
       $args = array(
		'post_type'              => array( 'item-archive' ),
		'nopaging'               => false,
		'posts_per_page'         => '5',
		'tax_query'              => array(
				'relation' => 'AND',
				array(
		'taxonomy'         => 'category',
		'terms'            => 'newsletter-manitoba',
		'field'            => 'slug',
		),   ),
		);

		// The Query
		$query = new WP_Query( $args );

			// The Loop
		if ( $query->have_posts() ) {
		while ( $query->have_posts() ) {
		$query->the_post();	?>	

And then after the page content section:

<?php 
	pagenavi(); 
	// Restore original Post Data
	wp_reset_postdata();
 ?>

Hi Parkinson_Canada,

The question is not related to our product and it is a customization question. This is unfortunately outside of our support scope and you need to consult with a developer.

If you are into coding you can start your research here.

Thank you for your understanding.

Thanks for the research link. It’s was helpful.

I now know that pagination with custom queries will only work if you pass the total number of pages in the query to paginate_links() using max_num_pages

I got this working, but I want to use the pagenavi function from x-theme, so that it looks similar to other paginated pages. Is this correct that pagenavi() comes from x-theme? I found pagination.php, so I’m quite sure that it does.

Do I have to pass max_num_pages to pagenavi(), or is this done automatically? Is there any documentation on using pagenavi() instead of native WP pagination functions?

Hi @Parkinson_Canada,

The pagenavi() function is a specific X theme function that works only with the standard post types of WordPress and our unique custom post type called Portfolio. We used that function in the files below:

framework/views/global/_index.php
framework/views/global/_portfolio.php

The function itself is added in the file below:

framework/functions/frontend/pagination.php

In order to make the pagenavi() work for other post types, you need to customize the function which is outside of our support scope. As a hint, please check the line 38 of the file which is using the is_single condition. That is only for the original post types if you want to have that for other post types you need to use is_singular. But even after that, you might need more customization to have it work correctly. That is why we do suggest that you go the original WordPress route and then style the pagination to be like the X theme.

To override the function to the child theme, you need to use this guide.

This is the most that we can be of help regarding the customization. I am sure you will understand that this is a customization matter and you will need to consult with a developer regarding this, and this is outside of our support scope.

Thank you for your understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.