Snippets

Rik Kendell Set different posts per page for custom post type archive

Created by Rik Kendell
// Set 'posts per page' for custom post type archive (cpt 'product')
	function ctp_posts_per_page( $query ) {    
	  if ($query->is_archive('product') && $query->is_main_query() && !is_admin()) {
	    // $ppp = get_option('posts_per_page');
        
        // Set posts per page to 12
	    $new_ppp = 12;
	    $query->set('posts_per_page', $new_ppp);	    
	  }      
	}
	add_action('pre_get_posts','ctp_posts_per_page');

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.