Before I go to your problem, I would like to start of by asking why you are using a custom query on a category page instead of the main query. You should never change the main query for a custom query on any archive page or on your home page.
WordPress provides an action hook, pre_get_posts
which you can use in conjunction with conditional tags to target and modify the main query before it is executed on specific pages. For category pages the is_category()
conditional check is supplied.
You could just simply do the following in your functions.php, while keeping your default loop in tact on your category page. Just a tip, pre_get_posts
uses the same parameters as WP_Query
function add_news_to_category( $query ) {
if ( !is_admin && $query->is_category() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'news' ) );
$query->set( 'posts_per_page', '9' );
$query->set( 'orderby', 'date' );
}
}
add_action( 'pre_get_posts', 'add_news_to_category' );
OK, now to your actual problem with your code.
-
Firstly, you don’t need to use
wp_reset_query
andwp_reset_postdata
together.wp_reset_query
is actually used in conjunction withquery_posts
, which you must never use, and I mean never. Just simply usewp_reset_postdata after
WP_Queryand
get_posts`, and remember, never forget to do that -
Secondly, look closer at your code. You have
$query = new WP_Query( $args_news );
, but then you have<?php next_posts_link( 'Older Posts', $custom_query->max_num_pages ); ?>
. Spot the difference?$query
and$custom_query
. So,<?php next_posts_link( 'Older Posts', $custom_query->max_num_pages ); ?>
should be<?php next_posts_link( 'Older Posts', $query->max_num_pages ); ?>
For further reading: