0

i made search plugin inside admin area and this code for search

var currpeged =1;
var pperpage=50;
jQuery(document).on('click','#search,#next,#prev',function(e) {
                // click search 
                 e.preventDefault();
                jQuery('.search-result').html('<p class="text-center"><img src="../wp-admin/images/loading.gif"></p>');


                if (jQuery('#showperpage').length == 1 ) {

                    pperpage = parseInt(jQuery('#showperpage').val());
                }

                var id=jQuery(this).attr('id');
                if(id == 'prev'){
                    if(currpeged <= 1){
                        currpeged=1;
                    } else{
                        currpeged-=1;
                    }
                } 

                if(id=='next'){
                    currpeged = currpeged + 1;  
                }
                var srch={
                    filter1:jQuery('#filter1'),
                    filter2:jQuery('#filter2'),
                    currp:currpeged,
                    perpage:pperpage,
                };

                    jQuery.post(ajaxurl,{
                        'action': 'search_do',
                        'param': srch
                    }
                    }).success(function(response){

                    jQuery('.search-result').html('');
                         for (var i = 0; i < response.length; i++) {
                                jQuery('.search-result').append(response[i]);
                        }
                    });
});

and the code for the php that take care of the search is :

    $param = $_POST['param'];
  $str_m='';
    if(is_array( $param)){
        $data = new stdClass();
        foreach ($param as $key => $value)
        {
            $data->$key = $value;
        }
    }
     $args_tt=array(); 
     $args=array(); 
     $query = new WP_Query(array( 
     'post_type'       =>    'custom-post',          // name of post type.
     'posts_per_page'  =>     100,
     'orderby'         =>    'meta_value_num',
     'meta_key'        =>    $str_m,
     'order'           =>    'ASC',
     'meta_query'      =>     $args,//filters
     'paged'          =>     intval($data->currp)+1 //from object

    ));

when i search i get results but the paging is not working the currp is never incremented and results still the same as before no pagination please help thank you .

  • Filter1: jQuert ?? I mean, maybe a typo, but will break srch and currentp will not be set. – Benoti Dec 20 '16 at 19:10
  • true but in when results come back from the while loop of WP_Query will have two buttons with #next & #prev and will set the srch again for pagination next page and previous page – sdx11 Dec 20 '16 at 19:45
  • If I understand well, you need to change these values on the success event. – Benoti Dec 20 '16 at 19:48
  • but i need to change them on click #next or #prev event so that user will be able when they click next and prev button will see the pagination – sdx11 Dec 20 '16 at 20:19
0

solution for this question was very simple in js code like this:

jQuery(document).on('click','#search',{
//search form submit
});
jQuery(document).on('click','#next',{
//next button clicked build search form + paged value
});
jQuery(document).on('click','#prev',{
//prev button clicked build search form + paged value
});
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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