I have googled this issue for the last 4 days, and everything I have found has not fixed the issue.
My Custom Post Type's Custom Taxonomy template paging 404's unless I set the sites Blog posts per page to 1, which I cannot do, due to the fact that there will be a need to show more than 1 "blog post" per page...
How can I correct this issue?
LATEST FIX ATTEMPT
// fix the paging 404's on category/tag pages
add_action( 'pre_get_posts', function( $qry ) {
$_num_per_page = ( get_option( 'gyokb_option_name' )['gyokb_articles_pp'] ) ?? 5;
if( ( is_tax( 'kb_categories' ) || is_tax( 'kb_tags' ) ) && ! is_admin() ) {
$qry->set ( 'post_type', array( 'post', 'gyo_kb' ) );
$qry->set( 'posts_per_page', $_num_per_page );
}
} );
My CPT is here... (too much code to paste here...) https://pastebin.com/SyKJwnCH
My Taxonomy is here... https://pastebin.com/4BWWgGWq
And My Paging in the template:
<?php
echo paginate_links( array(
'format' => 'page/%#%',
'prev_text'=>' Previous ',
'next_text'=>' Next ',
'current' => max( 1, $page ),
'total' => $pg_ct,
'type' => 'plain',
'mid_size' => 4,
'paged' => $page, ) );
?>
with my WP_Query
pulling it all together....
$args = array( 'post_type' => 'gyo_kb', 'posts_per_page' => $_num_per_page, 'paged' => $page,
'orderby' => 'date','order' => 'DESC',
'tax_query' => array(
array (
'taxonomy' => 'kb_categories',
'field' => 'slug',
'terms' => $cur_cat -> slug,
)
),
);
$the_query = new WP_Query( $args );
$page
is populated with: $page = get_query_var( 'page' ); $page = ( ! empty( $page ) ) ? $page : 1;
All other variables are populating properly
I had the fix applying during the incorrect "boot" timing for wordpress. Initially I had placed in in the "wp" action.
I moved it to the "init" action, and now it works.