Pagination not working in custom taxonomy endpoint with custom query

Posted in: Newspaper
Post count: 29

Ok, I know, my case is very specific (sorry).

I’m looking forward an structure like site.com/tv/game-of-thrones/news, where tv is a custom taxonomy, game-of-thrones is an item in this custom tax and news is a category item. The URL would return posts in both game-of-thrones and news item taxonomies.

To achieve this I created endpoints for the tv custom taxonomy item page (news, galleries, reviews and so on). Then I created a custom query in taxonomy-tv.php to filter dinamically by the two taxonomies itens. Here’s my code for the endpoint page:

$args = array(
'posts_per_page' => 4,
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'tv',
'field' => 'slug',
'terms' => array($current_term_obj->slug),
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array($uristr[2]),
),
),
'paged' => $paged,
);

$query = new WP_Query( $args );

if ($query->have_posts()) {
while ( $query->have_posts() ) : $query->the_post();
?>
"><?php the_title(); ?><br>
<?php
endwhile;
} else {
echo 'No post found';
}

query_posts( array( $query ) );
td_page_generator::get_pagination();
wp_reset_postdata();

Everything is great, but I can’t get this custom query to paginate. It returns the pagination menu, with the links, but it loads only the first page. Any ideas how I can fix it??

Thanks in advance!

Post count: 6535

Hi

I can’t point exactly to a solution but I assume that the issue is related with the usage of query_posts() function after the loop. You can try to use pre_get_posts hook to alter the query as it’s a beater approach in this regard: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

Hope this helps!
Thanks!

Post count: 29

Hi Andrei,

I tried this with this function, but still the same:

function my_post_queries( $query ) {
if (!is_admin() && $query->is_tax('tv')){
$query->set('posts_per_page', 4);
}
}
add_action( 'pre_get_posts', 'my_post_queries' );

Post count: 29

Any other ideas? I can provide an FTP and admin access if you want to check in details.

Post count: 6535

Hi

There is no need for ftp, the issue is most likely related by how queries are made for your custom taxonomy. Unfortunately I can’t debug or provide support in this regard as this task involve many investigations and also some tests in order to be completed.
We can’t offer customization services at the moment so if you still need guidance on this or you’re not aware of the steps you need to take in this regard please consider hiring a developer or a freelancer to do this for you.

Thanks for your understanding!

Viewing 5 posts - 1 through 5 (of 5 total)
The forum ‘Newspaper’ is closed to new topics and replies.