Title: Custom Post Type query not working
Last modified: August 21, 2016

---

# Custom Post Type query not working

 *  Resolved [Debabrata Karfa](https://wordpress.org/support/users/dkarfa/)
 * (@dkarfa)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/custom-post-type-query-not-working/)
 *     ```
       <?php  
   
                               $args = array (
                                   'post_type'          => 'artistspage',
                                   'posts_per_page'     => 6,
                                   'order'              => 'ASC',
                                   'orderby'            => 'modified',
                                   'paged'              => get_query_var('paged')
                               );
                               // The Query
                               $wp_query->query( $args );
                               while ( $wp_query->have_posts() ) : $wp_query->the_post();
                               ?>
                                   <div class="thumb-who">
                                       <a href="<?php the_permalink(); ?>">
                                       <?php the_post_thumbnail('who-thumb'); ?>
                                       </a>
                                       <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                                       <p><?php the_excerpt(); ?></p>
                                       <a href="<?php the_permalink() ?>" id="read-more" rel="bookmark">Read More ></a>
                                   </div>
                               <?php
   
                               endwhile;
                               wp_pagenavi( array( 'query' => $wp_query ) );
                               wp_reset_postdata();	// avoid errors further down the page
   
                           ?>
       ```
   
 * Give the results on the [http://domain.tld/artists/](http://domain.tld/artists/)
   but 404 error at [http://domain.tld/artists/page/2/](http://domain.tld/artists/page/2/)
 * [https://wordpress.org/plugins/wp-pagenavi/](https://wordpress.org/plugins/wp-pagenavi/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [domokun](https://wordpress.org/support/users/domokun/)
 * (@domokun)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/custom-post-type-query-not-working/#post-4691345)
 * Try replacing
 * `$wp_query->query( $args );`
 * with
 * `$wp_query = new WP_Query( $args );`
 * and go into Settings > Permalinks and click save.
 *  Thread Starter [Debabrata Karfa](https://wordpress.org/support/users/dkarfa/)
 * (@dkarfa)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/custom-post-type-query-not-working/#post-4691351)
 * Thanks for update me,
    I change that
 *     ```
       <?php  
   
                               $args = array (
                                   'post_type'          => 'artistspage',
                                   'posts_per_page'     => 6,
                                   'order'              => 'ASC',
                                   'orderby'            => 'modified',
                                   'paged'              => get_query_var('paged')
                               );
                               // The Query
                               $wp_query = new WP_Query( $args );
                               while ( $wp_query->have_posts() ) : $wp_query->the_post();
                               ?>
                                   <div class="thumb-who">
                                       <a href="<?php the_permalink(); ?>">
                                       <?php the_post_thumbnail('who-thumb'); ?>
                                       </a>
                                       <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                                       <p><?php the_excerpt(); ?></p>
                                       <a href="<?php the_permalink() ?>" id="read-more" rel="bookmark">Read More ></a>
                                   </div>
                               <?php
   
                               endwhile;
                               wp_pagenavi( array( 'query' => $wp_query ) );
                               wp_reset_postdata();	// avoid errors further down the page
   
                           ?>
       ```
   
 * In my Settings > Permalinks, I select Custom Structure and put this /%category%/%
   postname%/
 * But no success for me.
 * Where
 *     ```
       <?php
                               // WP_Query arguments
                               if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
                               elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
                               else { $paged = 1; }
                               $args = array (
                                   'category_name'          => 'news',
                                   'pagination'             => true,
                                   'posts_per_page'         => '6',
                                   'order'                  => 'ASC',
                                   'orderby'                => 'modified',
                                   'paged'                  => $paged
                               );
                               // The Query
                               $my_query = new WP_Query( $args );
                               while ( $my_query->have_posts() ) : $my_query->the_post();
                               ?>
                                   <div class="thumb-who">
                                       <a href="<?php the_permalink(); ?>">
                                       <?php the_post_thumbnail('who-thumb'); ?>
                                       </a>
                                       <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                                       <p><?php the_excerpt(); ?></p>
                                       <a href="<?php the_permalink() ?>" id="read-more" rel="bookmark">Read More ></a>
                                   </div>
                               <?php
                               endwhile;
                               wp_pagenavi( array( 'query' => $my_query ) );
                               wp_reset_postdata();	// avoid errors further down the page
                               ?>
       ```
   
 * Working fine for and Give results at [http://www.domain.tld/news/page/2/](http://www.domain.tld/news/page/2/)
   too
 * Working for Category Query but not working for Post_type
 * Thank you

Viewing 2 replies - 1 through 2 (of 2 total)

 The topic ‘Custom Post Type query not working’ is closed to new replies.

 * ![](https://ps.w.org/wp-pagenavi/assets/icon.svg?rev=977997)
 * [WP-PageNavi](https://wordpress.org/plugins/wp-pagenavi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-pagenavi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-pagenavi/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-pagenavi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-pagenavi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-pagenavi/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Debabrata Karfa](https://wordpress.org/support/users/dkarfa/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/custom-post-type-query-not-working/#post-4691351)
 * Status: resolved