posts wposts INNER JOIN $wpdb->postmeta m1 ON wposts.ID = m1.post_id INNER JOIN $wpdb->postmeta m2 ON wposts.ID = m2.post_id WHERE (wposts.post_type = 'post' OR wposts.post_type = 'page') AND m1.meta_key = 'Inici' AND m1.meta_value = '1' AND m2.meta_key = 'Ordre_inici' AND wposts.post_status = 'publish' GROUP BY ID ORDER BY CAST( m2.meta_value AS SIGNED ) ASC "; $totalposts = $wpdb->get_results($total, OBJECT); $ppp = intval(get_query_var('posts_per_page')); //sçon 11 per la resta de pàgines índex però a la home en volem 12 $ppp = intval(16); $wp_query->found_posts = count($totalposts); $wp_query->max_num_pages = ceil($wp_query->found_posts / $ppp); $on_page = intval(get_query_var('paged')); if($on_page == 0){ $on_page = 1; } $offset = ($on_page-1) * $ppp; $wp_query->request = "SELECT * FROM $wpdb->posts wposts INNER JOIN $wpdb->postmeta m1 ON wposts.ID = m1.post_id INNER JOIN $wpdb->postmeta m2 ON wposts.ID = m2.post_id WHERE (wposts.post_type = 'post' OR wposts.post_type = 'page') AND m1.meta_key = 'Inici' AND m1.meta_value = '1' AND m2.meta_key = 'Ordre_inici' AND wposts.post_status = 'publish' GROUP BY ID ORDER BY CAST( m2.meta_value AS SIGNED ) ASC LIMIT $ppp OFFSET $offset"; $pageposts = $wpdb->get_results($wp_query->request, OBJECT); ?> '; foreach ($pageposts as $post): setup_postdata($post); $category = get_the_category(); if ($category) : $tipus = 'catt' ; else: if (is_page_child($post, 2)) : $tipus = 'art'; //artistes elseif (is_page_child($post, 136)) : $tipus = 'desc'; //descàrregues elseif (is_page_child($post, 74)) : $tipus = 'desc'; //equip else : $tipus = 'pag'; endif; endif; include(TEMPLATEPATH . "/caixes.php"); endforeach; ?>