You have a few things wrong with you query. I will explain as I go along
Firstly, you should never use query_posts
to construct custom queries. This is not just my emphasis, but the codex as well. The one big problem with query_posts
is, it many circumstances, pagination fails
Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination).
Secondly, the parameter that you’ve used category_name
excepts a string, not an array.
Thirdly, you’ve run two occurences of query_posts
where only one is actually needed. This is also why your pagination out right fails
Fouthly, your next_posts_link
$max_pages
parameter should be set for custom queries, otherwise it will fail
OK, to come to the business end, you need to construct you custom query with WP_Query
, keeping in mind some of the points I’ve raised above.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // this section is correct, allows pagination
$args = array( //set-up arguments to pass to WP_Query
'category_name' => 'string of category slugs, not name', // can use 'cat' parameter with string of category ID
'posts_per_page' => 5,
'paged' = $paged
);
$query = new WP_Query( $args); //add arguments back to WP_Query
if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); //start the loop
<-----YOUR LOOP---->
endwhile;
<----YOUR PAGINATION---->
Remember next_posts_link should look something like 'next_posts_link( 'Older Entries', $query->max_num_pages );'
wp_reset_postdata();
endif;