• 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

    (@bcworkz)

    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.