<?php
/**
 * Function used to control pagination on post type tax, archive and search pages
 * @package Ultra WordPress Theme
 * @since 1.0
 * @author AJ Clarke : http://wpexplorer.com
 * @copyright Copyright (c) 2012, AJ Clarke
 * @link http://wpexplorer.com
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */

//get posts per page
$wpex_option_posts_per_page = get_option( 'posts_per_page' );

//add posts per page filter
add_action( 'init', 'wpex_modify_posts_per_page', 0);
function wpex_modify_posts_per_page() {
    add_filter( 'option_posts_per_page', 'wpex_option_posts_per_page' );
}

//modify posts per page
function wpex_option_posts_per_page( $value ) {

	global $wpex_option_posts_per_page;
	
	//tax pagination
    if( is_post_type_archive('portfolio') || is_tax('portfolio_category') || is_tax('portfolio_tag') ) {
		return of_get_option('portfolio_pagination', '12');
	}
	elseif( is_post_type_archive('services') || is_tax('services_category') || is_tax('services_tag') ) {
		return of_get_option('services_pagination', '12');
	}
	elseif( is_post_type_archive('faq') || is_tax('faq_category') || is_tax('faq_tag') ) {
		return of_get_option('faq_pagination', '12');
	}
	elseif( is_post_type_archive('staff') || is_tax('staff_category') || is_tax('staff_tag') ) {
		return of_get_option('staff_pagination', '12');
	}
	elseif( is_post_type_archive('testimonials') || is_tax('testimonials_category') ) {
		return of_get_option('testimonials_pagination', '-1');
	}
	elseif( is_search() ) {
		return 10;
	}
	else { return $wpex_option_posts_per_page; }
}