Title: Modifying Post Type Archive Query
Last modified: August 21, 2016

---

# Modifying Post Type Archive Query

 *  [ameraz](https://wordpress.org/support/users/ameraz/)
 * (@ameraz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/modifying-post-type-archive-query/)
 * Im using the following code to modify the ‘posts_per_page’ parameter of a Custom
   Post Type & Custom Taxonomy Archive, problem is that it is also modifying the
   Main Blog Page (is_home) query:
 *     ```
       function list_all_posts($query) {
       	if ( !is_admin() && $query->is_main_query() && ( is_post_type_archive('custom_post_type') || taxonomy_exists('custom_taxonomy') ) ) {
       		$query->set( 'posts_per_page', '-1' );
       	}	}
       add_action('pre_get_posts','list_all_posts');
       ```
   
 * Have also tried:
 *     ```
       function list_all_posts($query) {
       	if ( !is_admin() && $query->is_main_query() && !is_home() && ( is_post_type_archive('custom_post_type') || taxonomy_exists('custom_taxonomy') ) ) {
       			$query->set( 'posts_per_page', '-1' );
       	}	}
       add_action('pre_get_posts','list_all_posts');
       ```
   
 * I only want to change the query of the Custom Post Type & Custom Taxonomy Archive
   and leave the default Main Blog Page intact so ‘Blog pages show at most’ can 
   be modified in Settings > Reading as it normally would.
 * Any help would be very much appreciated.
    Cheers!

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/modifying-post-type-archive-query/#post-4475518)
 * Your second code works fine on my installation. I did insert values valid for
   my installation. Are you using the right values? Do you actually have a post 
   type called ‘custom_post_type’? The argument provided needs to be an actual post
   type name, the function does not apply to a generic any custom post type.
 * In the same vein do you really have a taxonomy named ‘custom_taxonomy’? The argument
   provided needs to be an actual taxonomy name, the function does not apply to 
   a generic any custom taxonomy.

Viewing 1 replies (of 1 total)

The topic ‘Modifying Post Type Archive Query’ is closed to new replies.

## Tags

 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/modifying-post-type-archive-query/#post-4475518)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
