I’m ordering my posts by a custom meta value named “size”.
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = 'size'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_date < NOW()
ORDER BY $wpdb->postmeta.meta_value DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
if ($pageposts):
global $post;
foreach ($pageposts as $post):
setup_postdata($post);
the_title();
endforeach;
endif;
wp_pagenavi(); //creates page navigation
At the same time I’m using the WP-pagenavi plugin to navigate the posts by pages. I have 10 posts on each page.
The problem: Posts are ordered separately in each page. How can I order posts in descending order through all pages?
Update: I might have found a solution but I’m not sure how to implement it in my code
http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html
$my_query = new WP_Query( array( 'tag' => 'foo', 'paged' => get_query_var('paged') ) );
while ( $my_query->have_posts() ) : $my_query->the_post();
the_title();
// more stuff here
endwhile;
wp_pagenavi( array( 'query' => $my_query ) );
wp_reset_postdata(); // avoid errors further down the page
I’ve found a SO post that can solve your problem :
How to sort a 'query_posts' function by custom field, while limiting posts by another custom field
There you will find a custom class extending
WP_Queryand allowing you to make a query ordered by a custom field, and to include thepagedquery var too.So the steps :
Past the
class PostsOrderedByMetaQuerycode somewhere like in yourfunctions.phpReplace your query by :
Use it !