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 have a form, in which users can select what taxonomy they want the posts filtered by. It works fine except that it doesn't paginate. When I click on the next page of results, it clears the query.

How do I get pagination to work?

http://www.leschinskidesign.com.php5-10.ord1-1.websitetestlink.com/?post_type=products

<?php if(isset($_POST["submit_filter"])):
    global $wp_query;

    $params_array = array();

    $params_array[] = array(
                'taxonomy' => 'factors',
                'field' => 'id',
                'terms' => $_POST["form_factors"]
            );

    $params_array[] = array(
                'taxonomy' => 'badges',
                'field' => 'id',
                'terms' => $_POST["form_attributes"]
            );

            if(count($_POST["form_attributes"])==0 or count($_POST["form_factors"])==0){
                $params_array['relation'] =  'OR';
            }else{
                $params_array['relation'] =  'AND';
            }
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array_merge( $wp_query->query_vars, array(
    'posts_per_page' => 1,
    'order' => 'ASC',
'paged=' => $paged, 
    'tax_query' =>$params_array
        ));

    query_posts( $args  );
endif; ?>

As suggested I also tried using pre_get_posts, but the issue remained.

function product_query($query) {

if ( is_post_type_archive( 'products' ) ) {

   if(isset($_POST["submit_filter"])):

$query->set('posts_per_page','2');

$params_array = array();

global $query_string;

$params_array[] = array(
            'taxonomy' => 'factors',
            'field' => 'id',
            'terms' => $_POST["form_factors"]
        );


$params_array[] = array(
            'taxonomy' => 'badges',
            'field' => 'id',
            'terms' => $_POST["form_attributes"]
        );


        if(count($_POST["form_attributes"])==0 or count($_POST["form_factors"])==0){
            $params_array['relation'] =  'OR';
        }else{
            $params_array['relation'] =  'AND';
        };




if( ! empty( $params_array ) )
        $query->set( 'tax_query', $params_array );
endif; 
}


}

add_action('pre_get_posts', 'product_query', 1);
share|improve this question
    
You setup the $paged value, but never pass it into the query. –  t31os Aug 10 '13 at 9:25
    
    
@t31os I tried passing it into the query with 'paged=' => $paged, but it didn't solve the issue. –  Picard102 Aug 13 '13 at 20:29
    
@s_ha_dum I tried to use pre_get_posts but the results still clear on navigation to the next page. –  Picard102 Aug 13 '13 at 20:30
    
And how are the $_POST fields still set at the point you click said link for the next page? –  t31os Aug 14 '13 at 10:27
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.