pre_get_posts


add_action('pre_get_posts','set_posts_argument');

function set_posts_argument( $query ) {
if ( ! is_admin() && is_post_type_archive('game')) {
$query->set('posts_per_page', 2);
}

if ( ! is_admin() && is_post_type_archive('device_game')) {

$query->set('posts_per_page', 500);

$user_agent= user_agent();

$meta_key = '';
if($user_agent=='android'){
$meta_key = 'android_link';
}elseif ($user_agent=='ios'){
$meta_key = 'ios_link';
}

if(!empty($meta_key)) {
$query->set('orderby', 'menu_order title');
$query->set('order', 'ASC');
$query->set('meta_query', array(
array(
'key' => $meta_key,
'value' => '',
'compare' => '!='
)
));
}
}
}

update wordpress loop

global $paged;global $wp_query;global $query_string;$wp_query->max_num_pages;$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;query_posts($query_string.'&posts_per_page=2&orderby=menu_order title&order=ASC');

// Start the Loop.while ( have_posts() ) : the_post();