Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the following code with query_posts to put together a custom search:

$args = array(
    'post_type' => 'species',
    'meta_query' => $meta_query,
    'tax_query' => $tax_query
);

$meta_query is put together with a few segments of code like this:

if (!empty($_POST["s_aquarium_H"])) {
    $val = convert_values('size', $size, $_POST["s_aquarium_H"]);
    $aquarium_H = array(
        'key' => 'aquarium_H',
        'value' => $val,
        'type' => 'numeric',
        'compare' => '<='
    );
    $meta_query[] = $aquarium_H;
}

This works perfectly well and is accessed by visiting /advanced-search/.

However, my pagination does not. When you click Next Entries, the URL changes to /advanced-search/page/2/ but simply re-opens the Advanced Search form.

I guess this is because I'm using $_POST. Is there a way of using pagination with $_POST or do I need to change my code to get_query_var or something?


EDIT

My rewrite rules appear to be correct: /advanced-search/page/2/ displays pagename: advanced-search, paged: 2 in Monkeyman's Rewrite Analyzer plugin.

Rewrite Rules


FURTHER EDIT

My advanced-search.php page uses the following code to determine whether it should show the search form or the results. I guess this needs re-writing if I'm to use pagination:

<?php if ( isset( $_POST["act"] ) && $_POST["act"] == "s" ) : ?>

Does anyone have any ideas as to how I could go about rewriting this? I guess GET instead of POST needs to be used?


Thanks in advance,

share|improve this question
    
Could you add error catching measures like an else case with a message, on the check for POST being set, or a wp_die('<pre>'.print_r($args,true).'</pre>'); if no posts are found? etc Give as much information about what the values of all variables are on failure and the path the code is taking –  Tom J Nowell Apr 5 '12 at 10:57
    
Also use php.net/manual/en/function.assert.php , e.g. use an assertion to make sure $val actually is numeric, and not null or a string or NaN or an error object etc –  Tom J Nowell Apr 5 '12 at 10:59
    
Hi Tom. The $args are displaying correctly in every instance - it's only when I click the Previous Entries button that everything goes wrong. I've added another edit to my OP with my suspicions. Could you have a look and see what you think? –  dunc Apr 8 '12 at 20:52
    
Scrap that, fixed it. :) –  dunc Apr 8 '12 at 21:05
add comment

3 Answers 3

Add this to your query:

'paged' => get_query_var('paged')

Like so:

$args = array(
    'post_type' => 'species',
    'meta_query' => $meta_query,
    'tax_query' => $tax_query,
    'paged' => get_query_var('paged')
);

Should do the trick.. Using Wp-pageNavi? dont forget to add the
wp-pagenavi tag just after the loop ends

<div class="navigation"><?php wp_pagenavi(); ?></div>

.
Hope This Helps ;)
Cheers, Sagive.

share|improve this answer
    
Hi Sagive. Thanks for this, but the same problem is occurring. I'm wondering if, on top of your code, I need some additional rewrite rules? –  dunc Mar 31 '12 at 21:00
    
Actually, no, it isn't that - the Rewrite Analyzer plugin says that my rewrite rules are correct. –  dunc Mar 31 '12 at 21:01
    
Sorry, dont know that plugin but.. have you tried it mate? can you give a link or are you working localy? –  Sagive SEO Mar 31 '12 at 21:28
    
Sorry, can't give you a working URL. I've updated my original post with an image of the results from the Rewrite Analyzer plugin. Basically it shows that my rewrite rules are correct, but even with your code, my pagination isn't working. Any idea? I defined $wp_query global too, just in case.. –  dunc Mar 31 '12 at 23:21
add comment
if (!empty($_REQUEST["s_aquarium_H"])) {
   $_GET["s_aquarium_H"] = $_REQUEST["s_aquarium_H"];
    $val = convert_values('size', $size, $_REQUEST["s_aquarium_H"]);
    $aquarium_H = array(
        'key' => 'aquarium_H',
        'value' => $val,
        'type' => 'numeric',
        'compare' => '<='
    );
    $meta_query[] = $aquarium_H;
}
share|improve this answer
    
Bounty awarded for coming closest to solving the problem. –  dunc Apr 8 '12 at 21:05
add comment
up vote 0 down vote accepted

In the end, this was nothing to do with pagination - as such.

I needed to change my entire form to GET method and $_REQUEST variables rather than POST and $_POST.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.