I have a simple AJAX pagination that seemed to work just fine, calling one Wordpress page (not ideal, I know) with a pagenum and a sort order arguments and it returned 4 custom posts per call. The problem I found while testing it is that if the items are ordered like this in the db:
item1: 4 votes item2: 3 votes item3: 3 votes item4: 3 votes ----page2---- item5: 3 votes item6: 2 votes ...
...there's a chance that any one of items with 3 votes in custom field will display as the first item on page2 of the pagination. This effectively erases one of the items from listing, and I can't seem to find a way to query get_posts properly.
This is how it looks now:
elseif($savjet_order == 'votes') : $offset = (($savjet_per_page * $savjet_page) /* - $savjet_per_page*/ ); //$offset = $offset < 0 ? 0 : $offset; $args = array( 'numberposts' => $savjet_per_page , 'offset' => $offset , 'meta_key' => 'wpcf-glasova', 'orderby' => 'meta_value_num post_date', 'order' => 'DESC', //'paged' => $savjet_page , 'post_type' => 'savjet', 'post_status' => 'publish' /*'suppress_filters' => true*/ ); $savjeti = get_posts($args);
...adding post_date (or even date) to orderby clause doesn't seem to change anything ('date' seems to make it worse by making the list ascend even though the order is DESC).