Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

elsnare on "Pagination problem on custom wp_query sort order"

$
0
0

Hello!

Some info:
1. I'm using a custom build wp_query to display a list of custom posts with some custom post fields. Works great.

2. I'm using the following code to sort the posts ASC/DESC depending on custom fields. Simple url GET with custom keys and values. Also works fine.

<a href="<?php echo esc_attr( add_query_arg( 'order', 'city_desc' ) ); ?>"></a>  

if (isset($_GET['order'])) {
$sort= $_GET['order'];

 if($sort == 'city_desc'){
                  $args['order'] = 'DESC'; $args['meta_key'] = 'city';
				  }

The problem
When I enable pagination and sort the results - everything seems fine at first: the order is ok, the posts get split ect. But when I enter the second page of results something strange happens.

Let's say I have 3 posts and a custom field 'price':

POST A - 100
POST B - 200
POST C - 300
Posts per page is set to 2.

Pagination page #1 after sorting DESC I get:

POST C - 300
POST B - 200

But on page #2 I get:

POST C - 300
and that's it

So it seems there is a conflict between the pagination function which returns a given number of posts (1 in this example) on the 2nd page, but uses the sorting, resulting in a duplicate of POST C.

Here are the URL for those pages:

For sorted results:
list_page/?order=price_desc

For page #2

some_page/page/2/?order=price_desc%2F

I'm using a plugin to do the pagination.

Any thoughts? :)


Viewing all articles
Browse latest Browse all 8245

Trending Articles