As I stated in comments, use pre_get_posts
to alter the main query. Never replace the main query with a custom one. Again, from comments
Just for starters, on each page load you are running the same query twice, it is slow, double the amount of db calls and pagination has to be tweaked to work almost 100 percent, this just to get the same posts 🙂
You can also check out this post I have done on the subject
To make the transition is quite easy, easier than you think. Here is how
-
Create a
taxonomy.php
template -
Add the following in there (I have added php tags to make space for your HTML mark up)
<?php while ( have_posts() ) { the_post(); ?> <?php get_template_part('templates/content-works', get_post_format()); ?> <?php } ?>
-
Now, you have to move your conditions to
functions.php
insidepre_get_posts
(Requires PHP 5.3+)add_action('pre_get_posts', function ($q) { if(!is_admin() && $q->is_main_query() && $q->is_tax()) { $q->set('post_type', 'works'); $q->set('posts_per_page', 40); $q->set('meta_key', 'wpcf-composition-date'); $q->set('orderby', 'wpcf-composition-date'); $q->set('order', 'DESC'); } return $q; }
This should be enough to make things work