I’m having an issue getting my custom taxonomy page to paginate correctly. I looked through other examples posted on this forum, but I could not get my second page to not return a 404 error page. Here are my details
- Custom Tax: Study_Tags
- Example Terms: Community, Economy, Crime…
- Custom Taxonomy Page: taxonomy-study_tags.php
- Posts Per Page: 5 (set in Reading Settings, global for all pages/posts on site)
I am using a Custom Post Type “Study” with the custom taxonomy “Study Tags”, which is why i feel I need to use the “query_posts()” function.
I only want to show parent pages in the results, as each “Study” CPT can have children page with study details, presentations… etc.
My information to setup the query
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array_merge( $wp_query->query_vars,
array(
'post_type'=> 'study',
'post_parent' => '0',
'paged' => $paged,
'order' => 'ASC',
));
query_posts($args);
?>
$wp_query->query_vars passes for example “[study_tags] => community” when var_dump() is used, so I know it is transmitting the correct term to the custom tax page.
Any ideas how to get a second page of results?
First of all: never use
query_posts
: when you need to change the main query, is a lot better use thepre_get_posts
hook: your site users will thank you, once performance will increase.If the custom taxonomy
study_tags
is used only forstudy
CPT the only reason to change default query is to set post parent to0
.Then in your
taxonomy-study_tags.php
template, you can just use the loop. Pagination will work without doing anything else.