I’m using categories and wp_query to create an “advanced search” feature on my website. It was working great until recently I noticed that the pagination was broken. The following 2 links should demonstrate the problem:
On page 1 I get 185 results:
But on subsequent pages the query string breaks:
You should see the second link redirect to:
http://www.barbadospropertylist.com/page/2/?budget=1000000&submit=Advanced%20Search
What with recent upgrades to WordPress I have no idea what might be causing this. Any pointers would be very, very welcome! I’ve been trying to figure this one out all day. 🙂
Here is my query code:
query_posts(
array_merge(
wp_query->query,
array(
'category__and' => $pladvsearchcatids,
'meta_key' => 'price',
'orderby' => 'meta_value_num',
'meta_compare' => '<=',
'meta_value' => $plbudget,
'order' => 'DESC'
)
)
);
Just noticed something really strange. When I download my site and work locally the problem goes away. The query string is not redirected on page 2 and paging through the results works as expected.
This might happen because you need to include the pagination information when you run custom queries with query_posts. Because custom query_post commands ignore any default values of the query_posts command. Here is an example of a query i have used to solve this problem in a simpler case (just to exclude a single category from the query):
Here is an example of how you can include this in your query. Don’t know if this works for you, try it out and give me feedback. 🙂
Please try the following code:
Note, that your
orberby
value accepts only numeric values. You could trymeta_value
instead, if your output are (eventually) strings. In this case, thecompare
statement of<=
won’t work.